Bug 53503 - Inconsitent behaviour of xaml x:TypeArguments when using nested generic arguments
Summary: Inconsitent behaviour of xaml x:TypeArguments when using nested generic argum...
Status: RESOLVED FIXED
Alias: None
Product: Forms
Classification: Xamarin
Component: Forms (show other bugs)
Version: unspecified
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2017-03-18 07:25 UTC by Alexis
Modified: 2017-07-19 11:59 UTC (History)
5 users (show)

Tags: xamlg
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

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!