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)

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


Attachments

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!

Notice (2018-05-21): bugzilla.xamarin.com will be switching to read-only mode on Thursday, 2018-05-25 22:00 UTC.

Please join us on Visual Studio Developer Community and GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs and copy them to the new locations as needed for follow-up. The See Also field on each Bugzilla bug will be updated with a link to its new location when applicable.

After Bugzilla is read-only, if you have new information to add for a bug that does not yet have a matching issue on Developer Community or GitHub, you can create a follow-up issue in the new location. Copy and paste the title and description from this bug, and then add your new details. You can get a pre-formatted version of the title and description here:

In special cases you might also want the comments:

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.

Note You need to log in before you can comment on or make changes to this bug.