xamarin/Xamarin.Forms

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

开放

#8,115 创建于 2019年10月21日

 (2 条评论) (0 个反应) (1 位负责人)C# (1,926 个派生)batch import
a/Xaml </>help wantedi/highinactivet/bug :bug:up-for-grabs

仓库指标

星标
 (5,644 个星标)
PR 合并指标
 (30 天内没有已合并 PR)

描述

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

贡献者指南