xamarin/Xamarin.Forms

[Bug] Xaml Code generation produces wrong code with generic base class

Aperta

#8115 aperta il 21 ott 2019

 (2 commenti) (0 reazioni) (1 assegnatario)C# (1926 fork)batch import
a/Xaml </>help wantedi/highinactivet/bug :bug:up-for-grabs

Metriche repository

Star
 (5644 stelle)
Metriche merge PR
 (Nessuna PR mergiata in 30 g)

Descrizione

Description

There seems to be a bug in Xaml code generation when using generic EventArgs.

I've created a generic base class containing logic that I want to share between views. This class contains an EventHandler with generic EventArgs which gets fired when the view's value changes. I've also created two subclasses that inherit from this class.

Now when using these views in Xaml, my code crashes in the InitializeComponent() with the following error:

System.InvalidCastException: "Unable to cast object of type 'System.EventHandler`1[Redacted.PickerValueChangedEventArgs`1[System.Nullable`1[System.DateTime]]]' to type 'System.EventHandler`1[Redacted.PickerValueChangedEventArgs`1[System.Nullable`1[System.TimeSpan]]]'."

Steps to Reproduce

  1. Clone the reproduction repo
  2. Start it (Platform shouldn't matter, but I testet it under UWP)
  3. The app crashes

Expected Behavior

The app doesn't crash and the EventHandlers are successfully registered

Actual Behavior

The app crashes with the above exception

Basic Information

  • Version with issue: 4.2.0.709249
  • Last known good version: -
  • IDE: Visual Studio 2019 Professional
  • Platform Target Frameworks:
    • UWP: 16299
  • Nuget Packages: -
  • Affected Devices: Windows 10 PC

Reproduction Link

Link

Guida contributor