Reputation: 10516
I have the dreaded 'Could not load file or assembly' and this time I ran out of options to fix it, hope you are smarter.
My (simplified) solution is this:
Since Client.dll is not .Net Core 5.0, I added System.Text.Json as a NuGet package. This leads to the following exception when calling RefreshTokenAsync on OidcClient:
System.IO.FileLoadException: 'Could not load file or assembly 'System.Text.Json, Version=5.0.0.2, 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 tried a couple of things but none have worked so far:
Add the closest version to 5.0.0.2 of System.Text.Json I could find (5.0.0, 5.0.1) to Client.dll, issue remains.
Add the latest version to 5.0.0.2 of System.Text.Json I could find (6.0.1) to Client.dll, issue remains.
Add a package redirect to Winforms.exe (even though Generate Auto Redirects = true):
<dependentAssembly>
<assemblyIdentity name="System.Text.Json" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral"/>
<bindingRedirect oldVersion="5.0.0.2" newVersion="6.0.1"/>
</dependentAssembly>
No dice
I'm not sure how to fix this anymore, any takers? Thanks so much in advance.
Upvotes: 1
Views: 1171
Reputation: 420
I did something similar with EF Core and EF6. Inside cproj add a condition:
<ItemGroup Condition=" '$(TargetFramework)' == 'net48' ">
<PackageReference Include="System.Text.Json" Version="5.0.0"></PackageReference>
</ItemGroup>
Then use preprocessor directives to load the assembly:
#if NET48
using System.Text.Json;
#endif
Upvotes: 1