This is Xamarin's bug tracking system. For product support, please use the support links listed in your Xamarin Account.
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 2017-04-06 18:10:19 UTC
https://github.com/xamarin/Xamarin.Forms/pull/857
Comment 4 Samantha Houts 2017-04-18 23:25:49 UTC
Should be fixed in 2.3.5-pre1. Thank you!

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