简体   繁体   English

如何解决 Framework 4.8 使用的 NetStandard 2.0 库中的 package 参考问题?

[英]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:我的(简化的)解决方案是这样的:

  • Winforms.exe, Framework 4.8. Winforms.exe,框架 4.8。 This references:这参考:
  • Client.dll, .Net Standard 2.0 which uses Client.dll,.Net Standard 2.0 使用
  • IdentityModel.OidcClient 5.0.0 which uses IdentityModel.OidcClient 5.0.0 使用
  • System.Text.Json System.Text.Json

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:我尝试了几件事,但到目前为止都没有奏效:

  1. 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,问题仍然存在。

  2. 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),问题仍然存在。

  3. 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没有骰子

  1. Tried adding the NuGet (all different versions) to WinForms.exe, with or without redirect.尝试将 NuGet(所有不同版本)添加到 WinForms.exe,无论是否重定向。 Issue remains.问题依然存在。

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.

相关问题 如何更改 netstandard 2.0 库使用的 Newtonsoft.Json 的版本 - How to change the version of Newtonsoft.Json used by netstandard 2.0 library 如何更新到.NETStandard 2.0 NuGet包 - How to update to .NETStandard 2.0 NuGet Package 在不同的 netstandard2.0 库 NU1202 中安装 netstandard2.0 Nuget 包 - Installing a netstandard2.0 Nuget Package inside a different netstandard2.0 library NU1202 将PowerShell包添加到.netstandard2.0类库中 - Add PowerShell package to .netstandard2.0 class library 如何从.NetStandard类库引用net40框架程序集? - How do I reference net40 framework assembly from .NetStandard class library? 如何使用 COM 参考构建 .NET Windows 库,它可以针对 .NET Framework 4.8 和 .NET 6? - How to build a .NET Windows library using a COM reference, that could target either .NET Framework 4.8 and .NET 6? 添加对netstandard 2.0的引用的问题 - Problems with adding reference to netstandard 2.0 在netstandard 2.0和netcore 2.0的最终版本中,为什么我们要构建netstandard2库,同时又可以使用完整的4.6.1框架 - With the final release of netstandard 2.0 and netcore 2.0, why we care to build netstandard2 library while we can use the full framework 4.6.1 如何从.NetStandard 2.0 class 库中播放声音? - how to play a sound from .NetStandard 2.0 class library? 针对 4.7.2 的 Asp.net 网站项目无法使用 MSBuild 解析 .netstandard 2.0 引用 - Asp.net website project targeting 4.7.2 cannot resolve .netstandard 2.0 reference using MSBuild
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM