Bug 53503

Summary: Inconsitent behaviour of xaml x:TypeArguments when using nested generic arguments
Product: Forms Reporter: Alexis <the.wench>
Component: FormsAssignee: Bugzilla <bugzilla>
Status: RESOLVED FIXED    
Severity: normal CC: david, jas, jimmy.garrido, sahou, v-sapaun
Priority: ---    
Version: unspecified   
Target Milestone: ---   
Hardware: PC   
OS: Windows   
Tags: xamlg Is this bug a regression?: ---
Last known good build:

Description Alexis 2017-03-18 07:25:06 UTC
According to the Microsoft documentation, x:TypeArguments in xaml can support nested generic type arguments by using parenthesis.  Xamarin's xaml parsing code doesn't always properly handle this.

The code in TypeArgumentsParser.Parse() in the file Xamarin.Forms.Xaml\TypeArgumentsParser.cs does seem to correctly handle nested type argument.

The code in XamlGTask.ParseXaml(), XamlGTask.GetNamesAndTypes() and XamlGTask.GetType()  in Xamarin.Forms.Build.Tasks\XamlGTask.cs however does not handle the nested type arguments and in particular generates invalid code in the .xaml.g.cs files if you attempt to use nested generic type arguments with x:Name.

The end result is that this xaml will work properly:
<?xml version="1.0" encoding="utf-8" ?>
<ResourceDictionary xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="Test.Test"
            xmlns:c="clr-namespace:System.Collections.Generic;assembly=System.Collections" xmlns:csr="clr-namespace:System.Collections.Generic;assembly=System.Runtime" >
    <c:List x:TypeArguments="csr:KeyValuePair(x:String,x:String)" x:Key="Test" >
        <csr:KeyValuePair x:TypeArguments="x:String,x:String" >
            <x:Arguments>
                <x:String>TheKey</x:String>
                <x:String>TheValue</x:String>
            </x:Arguments>
        </csr:KeyValuePair>
    </c:List>
</ResourceDictionary>
    
But this xaml causes a compiler error because of the x:Name
<?xml version="1.0" encoding="utf-8" ?>
<ResourceDictionary xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="Test.Test"
            xmlns:c="clr-namespace:System.Collections.Generic;assembly=System.Collections" xmlns:csr="clr-namespace:System.Collections.Generic;assembly=System.Runtime" >
    <c:List x:TypeArguments="csr:KeyValuePair(x:String,x:String)" x:Key="TestList" x:Name="TestListMember" >
        <csr:KeyValuePair x:TypeArguments="x:String,x:String" >
            <x:Arguments>
                <x:String>TheKey</x:String>
                <x:String>TheValue</x:String>
            </x:Arguments>
        </csr:KeyValuePair>
    </c:List>
</ResourceDictionary>
Comment 1 Jimmy [MSFT] 2017-03-20 15:41:32 UTC
Thank you for this report! Let me test with the code you provided to see if I can reproduce and confirm this issue, and I will update the report with my results.
Comment 2 Stephane Delcroix 2017-04-04 07:21:48 UTC
Yeah, I know, I know...

I'm quite sure it's for the reproduction case purposes only, but as a rule, you shouldn't x:Name your resources
Comment 3 Samantha Houts [MSFT] 2017-04-06 18:10:19 UTC
https://github.com/xamarin/Xamarin.Forms/pull/857
Comment 4 Samantha Houts [MSFT] 2017-04-18 23:25:49 UTC
Should be fixed in 2.3.5-pre1. Thank you!