dotnet icon indicating copy to clipboard operation
dotnet copied to clipboard

System.TypeInitializationException: 'The type initializer for 'CommunityToolkit.Mvvm.Messaging.WeakReferenceMessenger' threw an exception.'

Open DSBloom opened this issue 3 years ago • 2 comments

Describe the bug

I upgraded my NuGet references from the old Microsoft.Toolkit.Mvvm to the new CommunityToolkit.Mvvm, and now my project will not run. It will build, but I cannot debug. I get the following error: System.TypeInitializationException: 'The type initializer for 'CommunityToolkit.Mvvm.Messaging.WeakReferenceMessenger' threw an exception.

FileNotFoundException: Could not load file or assembly 'System.Runtime.InteropServices.RuntimeInformation, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.

I noticed that 'System.Runtime.InteropServices.RuntimeInformation` was listed as a transitive package in the NuGet package manager UI, so I installed it as a Top-level package, but that did not help.

Regression

7.1.0

Steps to reproduce

I tried to reproduce this with a new WPF dotnet framework 4.8 project and I couldn't.

Expected behavior

I expect the application to launch.

Screenshots

image

IDE and version

VS 2022

IDE version

Microsoft Visual Studio Professional 2022 Version 17.3.1 VisualStudio.17.Release/17.3.1+32811.315 Microsoft .NET Framework Version 4.8.04084

Nuget packages

  • [ ] CommunityToolkit.Common
  • [ ] CommunityToolkit.Diagnostics
  • [ ] CommunityToolkit.HighPerformance
  • [X] CommunityToolkit.Mvvm (aka MVVM Toolkit)

Nuget package version(s)

8.0.0

Additional context

No response

Help us help you

No, just wanted to report this

DSBloom avatar Aug 23 '22 18:08 DSBloom

Using Dependency Walker it looks like System.Runtime.InteropServices.RuntimeInformation is referenced by the netstandard.dll, and is on my system at "C:\Windows\Microsoft.NET\assembly\GAC_MSIL\System.Runtime.InteropServices.RuntimeInformation\v4.0_4.0.0.0__b03f5f7f11d50a3a" so I don't know why I am getting a file not found error.

DSBloom avatar Aug 23 '22 18:08 DSBloom

I removed the following section from my app's .config file and my app launched. I think this is the same issue here #https://github.com/dotnet/standard/issues/567#issue-270127054

<dependentAssembly>
        <assemblyIdentity name="System.Runtime.InteropServices.RuntimeInformation" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.0.2.0" newVersion="4.0.2.0" />
 </dependentAssembly>```

DSBloom avatar Aug 23 '22 20:08 DSBloom