简体   繁体   English

无法加载文件或程序集“System.IO,Version=4.0.0.0,Culture=neutral,PublicKeyToken=b03f5f7f11d50a3a”或其依赖项之一

[英]Could not load file or assembly 'System.IO, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies

Over the last few days, I have been desperately trying to resolve a case of dependency hell I got into after installing a NuGet package which added a bunch of new dependencies from the System.Collections.* , System.Diagnostics.* , System.IO.* , System.Runtime.* , System.Text.* , System.Threading.* and System.Xml.* namespaces.在过去的几天里,我一直在拼命地尝试解决我在安装 NuGet package 后遇到的依赖地狱问题,它添加了一堆来自System.Collections.*System.Diagnostics.*System.IO.*的新依赖项System.IO.*System.Runtime.*System.Text.*System.Threading.*System.Xml.*命名空间。 The MVC project I have the issue in targets.Net 4.7.1 currently. MVC 项目我目前在 targets.Net 4.7.1 中遇到问题。

The package installation adds the following binding redirects to my web.config package 安装将以下绑定重定向添加到我的 web.config

  <dependentAssembly>
    <assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-4.1.2.0" newVersion="4.1.2.0" />
  </dependentAssembly>
  <dependentAssembly>
    <assemblyIdentity name="System.Runtime.InteropServices" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-4.1.2.0" newVersion="4.1.2.0" />
  </dependentAssembly>
  <dependentAssembly>
    <assemblyIdentity name="System.IO" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-4.1.2.0" newVersion="4.1.2.0" />
  </dependentAssembly>
  <dependentAssembly>
    <assemblyIdentity name="System.Reflection" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-4.1.2.0" newVersion="4.1.2.0" />
  </dependentAssembly>
  <dependentAssembly>
    <assemblyIdentity name="System.Runtime.Extensions" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-4.1.2.0" newVersion="4.1.2.0" />
  </dependentAssembly>
  <dependentAssembly>
    <assemblyIdentity name="System.Linq" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-4.1.2.0" newVersion="4.1.2.0" />
  </dependentAssembly>
  <dependentAssembly>
    <assemblyIdentity name="System.Xml.ReaderWriter" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-4.1.1.0" newVersion="4.1.1.0" />
  </dependentAssembly>
  <dependentAssembly>
    <assemblyIdentity name="System.Linq.Expressions" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-4.1.2.0" newVersion="4.1.2.0" />
  </dependentAssembly>

…which results in the exception below: …导致以下异常:

Could not load file or assembly 'System.IO, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. Reference assemblies should not be loaded for execution.  They can only be loaded in the Reflection-only loader context. (Exception from HRESULT: 0x80131058)

The highlighted line in the web.config is: web.config 中突出显示的行是:

<add assembly="System.IO, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />

I eventually found out that if I removed the bindingRedirect for System.IO it cleared that error and then complained about one of the other items in the list of binding redirects.我最终发现,如果我删除 System.IO 的System.IO ,它会清除该错误,然后抱怨绑定重定向列表中的其他项目之一。 One by one I removed all of the binding redirects and the problem is resolved.我一一删除了所有绑定重定向,问题就解决了。

I'm struggling to understand what is going on here.我很难理解这里发生了什么。 As an example, if I take a look at the property inspector for System.IO in my references in the Visual Studio project it points to C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.7.1\Facades\System.IO.dll and not the Nuget folder yet if I open the.csproj file in another editor I can see that the reference does, in fact, look as follows:例如,如果我在 Visual Studio 项目的引用中查看 System.IO 的属性检查器,它指向C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.7.1\Facades\System.IO.dll而不是 Nuget 文件夹,但如果我在另一个编辑器中打开 .csproj 文件,我可以看到引用确实如下所示:

<Reference Include="System.IO, Version=4.1.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
  <HintPath>..\packages\System.IO.4.3.0\lib\net462\System.IO.dll</HintPath>
  <Private>True</Private>
  <Private>True</Private>
</Reference>

Something is definitely wrong here because there are duplicate <Private>True</Private> entries, I've corrected this once but they are added back.这里肯定有问题,因为有重复的<Private>True</Private>条目,我已经更正了一次,但它们又被加回来了。 This is an issue for all of the new assemblies.这是所有新组件的问题。 I wonder if there is an issue with the Nuget packages somewhere?我想知道 Nuget 包是否有问题?

Any help/advice would be appreciated please.如有任何帮助/建议,我们将不胜感激。

I wonder if there is an issue with the Nuget packages somewhere?我想知道某个地方的 Nuget 包是否有问题?

Yes, this should be the issue for the nuget package.是的,这应该是 nuget 包的问题。 Some nuget packages take a dependency on NETStandard.Library , it will pull-in those system.* dependencies, on the other hand, some nuget package install dependencies under the .NET Standard framework incorrectly, I have even reported it here and here , this issue is related to the nuget package itself, we need to contact to the author of this package to update this package.一些 nuget 包依赖于NETStandard.Library ,它会NETStandard.Library那些system.*依赖,另一方面,一些 nuget 包错误地安装了 .NET Standard 框架下的依赖,我什至这里这里都报告,这个问题与nuget包本身有关,我们需要联系这个包的作者来更新这个包。

Above may be the reason that you got into after installing a NuGet package which added a bunch of system.* dependencies.以上可能是您在安装 NuGet 包后进入的原因,该包添加了一堆system.*依赖项。 Meanwhile, .NET Framework 4.7.1 adds support for .NET Standard in-box, we no need to add those system.* nuget package to the package.同时,.NET Framework 4.7.1 增加了对 .NET Standard in-box 的支持,我们不需要将那些 system.* nuget 包添加到包中。 When other nuget package pull in those system.* dependencies packages, nuget/VS will add binding redirect to the web.config file for those package from nuget, but VS use those system.* from .net framework by default, in this case, VS may not find the those system.* dependencies due to the binding redirect.当其他 nuget 包拉入那些system.*依赖包时,nuget/VS 会将绑定重定向添加到来自 nuget 的那些包的 web.config 文件,但 VS 默认使用来自 .net 框架的那些system.* ,在这种情况下,由于绑定重定向,VS 可能找不到那些system.*依赖项。 That the reason why you got the error "Could not load file or assembly 'System.IO...".这就是您收到错误“无法加载文件或程序集'System.IO ...”的原因。

To resolve this issue, the workaround is remove the binding redirects from the web.config file for the assemblies.要解决此问题,解决方法是从程序集的 web.config 文件中删除绑定重定向。 Check the thread .NET Standard issues on .NET Framework 4.7.1 for some details.有关详细信息,请检查.NET Framework 4.7.1 上的线程.NET Standard 问题

Besides, If you do not want add those System dependencies to your project you can delete them from your project.此外,如果您不想将这些系统依赖项添加到您的项目中,您可以将它们从您的项目中删除。

Hope this helps.希望这可以帮助。

I had similar problems with Sytem.IO assembly in Visual Studio 2022 and.Net 4.8.我在 Visual Studio 2022 和 .Net 4.8 中遇到了类似的 Sytem.IO 程序集问题。 I did solve this with these two steps:我确实通过以下两个步骤解决了这个问题:

  1. Re-install the NuGet package. If an upgrade is available you can just upgrade.重新安装NuGet package。如果有升级可以直接升级。

  2. Deleted "bin" and "obj" folders.删除了“bin”和“obj”文件夹。

After that, the project just loaded without any problems.在那之后,项目刚刚加载没有任何问题。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法加载文件或程序集“ System.Configuration,版本= 4.0.0.0,区域性=中性,PublicKeyToken = b03f5f7f11d50a3a”或其依赖项之一 - Could not load file or assembly 'System.Configuration, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies 无法加载文件或程序集“System.Runtime,Version=4.0.0.0,Culture=neutral,PublicKeyToken=b03f5f7f11d50a3a”或其依赖项之一 - Could not load file or assembly 'System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies 无法加载文件或程序集“System.Net.Http,Version=4.0.0.0,Culture=neutral,PublicKeyToken=b03f5f7f11d50a3a” - Could not load file or assembly "System.Net.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" 未找到此程序集:“System.Net.Http,版本=4.0.0.0,文化=中性,PublicKeyToken=b03f5f7f11d50a3a” - This assembly is not found: 'System.Net.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' Azure应用服务 - 无法加载文件或程序集&#39;System.Net.Http,Version = 4.2.0.0,Culture = neutral,PublicKeyToken = b03f5f7f11d50a3a&#39; - Azure app service - Could not load file or assembly 'System.Net.Http, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' linqpad无法加载文件或程序集&#39;System.Runtime,版本= 4.1.0.0,区域性=中性,PublicKeyToken = b03f5f7f11d50a3a&#39; - linqpad Could not load file or assembly 'System.Runtime, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' 无法加载文件或程序集“System.Runtime,版本=4.2.1.0,文化=中性,PublicKeyToken=b03f5f7f11d50a3a” - Could not load file or assembly 'System.Runtime, Version=4.2.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' &#39;无法加载文件或程序集&#39;System.Runtime,版本= 4.1.0.0,区域性=中性,PublicKeyToken = b03f5f7f11d50a3a&#39; - 'Could not load file or assembly 'System.Runtime, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' NET 核心 - 无法加载文件或程序集'System.Runtime,版本 = 6.0.0.0,文化 = 中性,PublicKeyToken = b03f5f7f11d50a3a',.NET 6 - NET core - Could not load file or assembly 'System.Runtime, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a ', .NET 6 无法从程序集“System.Web,版本=4.0.0.0,Cult=neutral,PublicKeyToken=b03f5f7f11d50a3a”加载类型“System.Web.UI.ParseChildrenAttribute” - Could not load type 'System.Web.UI.ParseChildrenAttribute' from assembly 'System.Web, Version=4.0.0.0, Cult=neutral, PublicKeyToken=b03f5f7f11d50a3a'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM