CommunityToolkit / dotnet

.NET Community Toolkit is a collection of helpers and APIs that work for all .NET developers and are agnostic of any specific UI platform. The toolkit is maintained and published by Microsoft, and part of the .NET Foundation.
https://docs.microsoft.com/dotnet/communitytoolkit/?WT.mc_id=dotnet-0000-bramin
Other
2.98k stars 293 forks source link

MVVM.Toolkit: WeakReferenceMessenger.Send throws System.IO.FileLoadException #86

Closed DhananjayDhamale closed 2 years ago

DhananjayDhamale commented 2 years ago

Describe the bug

Hi All,

We are migrating our class library application from MVVMLight to MVVMToolkit. We are using latest nuget package (V 7.1.2) We are using WeakReferenceMessenger to send message.

WeakReferenceMessenger.Default.Send(new XXXLoaded(this)); The send call throws "System.IO.FileLoadException" as below -

System.IO.FileLoadException: 'Could not load file or assembly 'System.Buffers, Version=4.0.2.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)'

I have analyzed more and found that Microsoft.Toolkit.Mvvm refers System.Buffer with ver 4:0:2:0 and it also refers System.Memory which internally refers System.Buffer with ver 4:0:3:0. As nuget package installs latest version of System.Buffer (due to compatibility), application throws runtime exception.

Note: I cannot use .config file to redirect versions. MVVMToolKit-MANIFEST System Memory_Manifest

Regression

7.1.2

Reproducible in sample app?

Steps to reproduce

Did not try in Sample app.

Expected behavior

WeakReferenceMessenger.Default.Send should not throw exception.

Screenshots

No response

Windows Build Number

Other Windows Build number

No response

App minimum and target SDK version

Other SDK version

No response

Visual Studio Version

2017

Visual Studio Build Number

15.9.13

Device form factor

No response

Nuget packages

Microsoft.Toolkit.Mvvm Version 7.1.2

Additional context

No response

Help us help you

Yes, but only if others can assist.

ghost commented 2 years ago

Hello DhananjayDhamale, 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 🙌

Sergio0694 commented 2 years ago

Hi @DhananjayDhamale, what runtime are you targeting? Are you on .NET Framework by any chance?

DhananjayDhamale commented 2 years ago

Hi @DhananjayDhamale, what runtime are you targeting? Are you on .NET Framework by any chance?

Hi Sergio0694, I am using .NET Framework 4.8.

Sergio0694 commented 2 years ago

Ah, I see. This is an issue with how .NET Framework resolves assembly binding redirects when referencing packages that have indirect references to any of the OOB libraries from the BCL (eg. System.Memory in this case). It's not something we can address from the Toolkit, as we're just targeting .NET Standard 2.0 in this case and pulling those dependencies in, which are also for .NET Standard. You will have to address this on your end by manually configuring binding redirects for this assembly 🥲

view21cy commented 1 year ago

i also have this probelm. would you please show the code how to modify this? "manually configuring binding redirects for this assembly”??

whit-tj commented 4 months ago

Anyone find out how to handle this? I can't get any binding redirects to resolve this issue. Uninstalling and reinstalling but the binding redirects seem to have 0 effect. Is there any combo of dependency versions that work? 7.0.2 worked but we need the bug fixes in 7.1.2,