CommunityToolkit / WindowsCommunityToolkit

The Windows Community Toolkit is a collection of helpers, extensions, and custom controls. It simplifies and demonstrates common developer tasks building .NET apps with UWP and the Windows App SDK / WinUI 3 for Windows 10 and Windows 11. The toolkit is part of the .NET Foundation.
https://docs.microsoft.com/windows/communitytoolkit/
Other
5.9k stars 1.37k forks source link

TypeLoadException in Release using Behaviors with an ICommand #4022

Open alove-kahua opened 3 years ago

alove-kahua commented 3 years ago

Describe the bug

Using a Behavior that has an ICommand property fails to run in Release build when using a standard Binding in XAML as such:

<Interactivity:Interaction.Behaviors>
    <Core:EventTriggerBehavior EventName="PointerPressed">
        <Core:InvokeCommandAction Command="{Binding TestCommand}" />
    </Core:EventTriggerBehavior>
</Interactivity:Interaction.Behaviors>

The exception is as follows:

Exception thrown at 0x755FA6E2 (KernelBase.dll) in CommandIssue.exe: WinRT originate error - 0x80131522 : 'System.TypeLoadException: Could not find Windows Runtime type 'System.Windows.Input.ICommand'.
   at System.StubHelpers.WinRTTypeNameConverter.GetTypeFromWinRTTypeName(String typeName, Boolean& isPrimitive)
   at System.StubHelpers.SystemTypeMarshaler.ConvertToManaged(TypeNameNative* pNativeType, Type& managedType)
   at Windows.UI.Xaml.Markup.IXamlType.get_UnderlyingType()
   at Microsoft.Toolkit.Uwp.UI.Controls.Core.Microsoft_Toolkit_Uwp_UI_Controls_Core_XamlTypeInfo.XamlTypeInfoProvider.GetXamlTypeBy'.
onecore\com\combase\winrt\error\restrictederror.cpp(1016)\combase.dll!764711A5: (caller: 76387BB6) ReturnHr(1) tid(10ec) 8007007E The specified module could not be found.
Exception thrown at 0x755FA6E2 (KernelBase.dll) in CommandIssue.exe: WinRT originate error - 0x802B000A : 'Cannot deserialize XBF metadata property list as 'Command' was not found in type 'Microsoft.Xaml.Interactions.Core.InvokeCommandAction'. [Line: 0 Position: 0]'.

This issue does not occur when the WCT is not referenced or if running the Debug build.

Steps to Reproduce

CommandIssue.zip

Steps to reproduce the behavior:

  1. Given the following environment (Sample App w/ XAML)
  2. Build in the Release Configuration.
  3. Start debugging the application from Visual Studio (while still in Release Configuration).
  4. See error

Expected behavior

The exception does not occur and runs correctly.

Screenshots

Environment

NuGet Package(s): 
Microsoft.NETCore.UniversalWindowsPlatform (6.2.12)
Microsoft.Xaml.Behaviors.Uwp.Managed (2.0.1)
Microsoft.Toolkit.Uwp.UI.Controls (7.0.1)

Package Version(s): 

Windows 10 Build Number:
- [ ] Fall Creators Update (16299)
- [ ] April 2018 Update (17134)
- [ ] October 2018 Update (17763)
- [ ] May 2019 Update (18362)
- [X] May 2020 Update (19041)
- [ ] Insider Build (build number: )

App min and target version:
- [ ] Fall Creators Update (16299)
- [ ] April 2018 Update (17134)
- [ ] October 2018 Update (17763)
- [X] May 2019 Update (18362)
- [ ] May 2020 Update (19041)
- [ ] Insider Build (xxxxx)

Device form factor:
- [X] Desktop
- [ ] Xbox
- [ ] Surface Hub
- [ ] IoT

Visual Studio 
- [ ] 2017 (version: )
- [X] 2019 (version: 16.9.5) 
- [ ] 2019 Preview (version: )

Additional context

Add any other context about the problem here.

ghost commented 3 years ago

Hello alove-kahua, thank you for opening an issue with us!

I have automatically added a "needs triage" label to help get things started. Our team will analyze and investigate the issue, and escalate it to the relevant team if possible. Other community members may also look into the issue and provide feedback 🙌

alove-kahua commented 3 years ago

Still fails in 7.0.2.

Kyaa-dost commented 3 years ago

Based on the above repro above i am seeing this error. Unhandled exception at 0x09185F61 (Windows.UI.Xaml.dll) in CommandIssue.exe: 0xC000027B: An application-internal exception has occurred (parameters: 0x0AC7EF48, 0x00000005).

Let's see if any community member can take a look at the code.

alove-kahua commented 3 years ago

@Kyaa-dost You can get more details if your Debugger type is set for Mixed (Managed and Native) in the project properties.

curia-damiano commented 3 years ago

Hi, we are facing the same issue, even with Debug builds.

michael-hawker commented 3 years ago

I believe this to be the same issue we're tracking with WinUI here, though in that case we're only seeing the issue in Debug mode.