Bug 57574 - When Generics EventHandler is set with XAML, it falls
Summary: When Generics EventHandler is set with XAML, it falls
Status: RESOLVED FIXED
Alias: None
Product: Forms
Classification: Xamarin
Component: Forms ()
Version: 2.3.4
Hardware: All All
: --- normal
Target Milestone: ---
Assignee: Bugzilla
URL: https://github.com/nuitsjp/XFGenericE...
Depends on:
Blocks:
 
Reported: 2017-06-17 06:45 UTC by Atsushi Nakamura
Modified: 2017-08-14 18:07 UTC (History)
5 users (show)

Tags: ac xamlc generics fr
Is this bug a regression?: No
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 Atsushi Nakamura 2017-06-17 06:45:36 UTC
When registering an EventHandler with a type parameter on an object with a type parameter specified in XAML, the following error occurs.

> System.BadImageFormatException: Method with open type while not compiling gshared

If register events only from the .cs file, it works normally.  
The sample code is as follows.


public class NotificationEventArgs<T> : EventArgs
{
    public T Message { get; set; }
}

public class Notificator<T>
{
    public event EventHandler<NotificationEventArgs<T>> Notified;
}


Setting these event handlers with XAML using these causes an error.

<local:Notificator x:Name="MyNotificator"
                    x:TypeArguments="x:String"
                    Notified="OnNotified"/>


The following code works normally.

MyNotificator.Notified += OnNotified;


I will release the reproduction code to Github.
https://github.com/nuitsjp/XFGenericEventSample
Comment 1 Jimmy [MSFT] 2017-06-22 21:07:37 UTC
I was able to reproduce this issue with the project provided in the description. This appears to be related to XamlC since the app does _not_ crash when it is disabled. I am confirming the report and we will investigate further.

### Version Tests
2.3.6.112   BAD
2.3.5-pre3  BAD
2.3.4.247   BAD
Comment 2 Stephane Delcroix 2017-06-27 09:20:38 UTC
https://github.com/xamarin/Xamarin.Forms/pull/1020