[英]How to resolve package reference issue in NetStandard 2.0 library used by Framework 4.8?
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.由于 Client.dll 不是.Net Core 5.0,我将 System.Text.Json 添加为 NuGetEFE4B70A8E603E687C This leads to the following exception when calling RefreshTokenAsync on OidcClient:这导致在 OidcClient 上调用 RefreshTokenAsync 时出现以下异常:
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.将我能找到的 System.Text.Json (5.0.0, 5.0.1) 的最接近的版本添加到 Client.dll,问题仍然存在。
Add the latest version to 5.0.0.2 of System.Text.Json I could find (6.0.1) to Client.dll, issue remains.将最新版本的 System.Text.Json 的 5.0.0.2 添加到 Client.dll 我可以找到(6.0.1),问题仍然存在。
Add a package redirect to Winforms.exe (even though Generate Auto Redirects = true):添加 package 重定向到 Winforms.exe(即使 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.提前非常感谢。
I did something similar with EF Core and EF6.我对 EF Core 和 EF6 做了类似的事情。 Inside cproj add a condition:在 cproj 里面添加一个条件:
<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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.