【问题标题】:Could not load file or assembly Exception from HRESULT: 0x80131040无法从 HRESULT 加载文件或程序集异常:0x80131040
【发布时间】:2014-02-23 20:27:59
【问题描述】:

我创建了我的第一个 MVC 4 项目,它可以在本地服务器上完美运行。但是当我将它发布到本地文件夹并将文件夹内容上传到托管服务器时。我尝试运行它并收到此错误:

无法加载文件或程序集“DotNetOpenAuth.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=2780ccd10d57b246”或其依赖项之一。该系统找不到指定的文件。 谁能帮帮我?

Web.config:

<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
  <dependentAssembly>
    <assemblyIdentity name="DotNetOpenAuth.Core" publicKeyToken="2780ccd10d57b246" />
    <bindingRedirect oldVersion="1.0.0.0-4.0.0.0" newVersion="4.1.0.0" />
  </dependentAssembly>
  <dependentAssembly>
    <assemblyIdentity name="DotNetOpenAuth.AspNet" publicKeyToken="2780ccd10d57b246" />
    <bindingRedirect oldVersion="1.0.0.0-4.0.0.0" newVersion="4.1.0.0" />
  </dependentAssembly>
  <dependentAssembly>
    <assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
    <bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
  </dependentAssembly>
  <dependentAssembly>
    <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
    <bindingRedirect oldVersion="1.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
  </dependentAssembly>
  <dependentAssembly>
    <assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
    <bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
  </dependentAssembly>
  <dependentAssembly>
    <assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" />
    <bindingRedirect oldVersion="1.0.0.0-1.3.0.0" newVersion="1.3.0.0" />
  </dependentAssembly>
</assemblyBinding>

P.S Web Forms 中的同一个项目适用于托管服务器。

【问题讨论】:

  • 您是否检查过.dll 是否存在于您编译站点的.bin 文件夹中?
  • 确保您在 dll 上选择了“复制本地”。这些可能是棘手的错误,因为错误中的 dll 有时不是“其依赖项之一”的问题。最后的办法是在服务器上安装框架。
  • 你的主机支持 MVC 吗?
  • 但是当我在本地服务器上运行相同的已发布项目时它可以工作!
  • 如何检查主机是否支持 MVC?

标签: asp.net asp.net-mvc asp.net-mvc-4 visual-studio-2012


【解决方案1】:

终于找到答案了!! 转到参考 -> 对导致问题的 dll 文件进行右键单击 -> 选择属性 -> 检查版本 -> 将属性中的版本与 Web 配置匹配

<dependentAssembly>
    <assemblyIdentity name="YourDllFile" publicKeyToken="2780ccd10d57b246"               culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-YourDllFileVersion" newVersion="YourDllFileVersion" />
  </dependentAssembly>

【讨论】:

  • 这个解决方案在我使用 而不仅仅是 之前不起作用。
  • 我的网络配置已经有了正确的版本。这对我不起作用
  • 我遇到了这个问题的一个变种,终于弄明白了。我的 web.config 看起来不错。并且项目在 .NET 中构建没有错误,但在发布期间收到警告。我在我的 csproj 文件中发现了对 ANTLR3.Runtime 的两个引用。软件包更新的残余。通过在记事本中编辑 csproj 将其删除,警告消失了。
【解决方案2】:

立即对我有用的是:

  • 我找到了 bin 文件夹(如下图所示)。

  • 为安全起见,将所有 dll 移至其他文件夹。

  • 然后重新构建项目。

  • 解决问题后,删除旧的dll文件。

【讨论】:

  • 这成功了。我懒得遵循其他建议。这看起来更简单。我认为问题是由于同一解决方案中的不同项目对同一 nuget 包具有不同版本而引起的。
【解决方案3】:

如果您的解决方案包含两个相互交互的项目并且都使用同一个引用,并且如果两个项目中各自引用的版本不同;然后也发生了这样的错误。不断更新所有对最新的引用。

【讨论】:

    【解决方案4】:

    我遇到了同样的问题,NuGet 包版本与项目中引用的版本不同。我必须更改配置上的版本以匹配项目引用中的版本。转到参考 -> 右键单击​​导致问题的 dll 文件 -> 选择属性 -> 检查版本 -> 将属性中的版本与 Web 配置匹配。这应该可以解决问题。

    【讨论】:

      【解决方案5】:

      将以下dll文件添加到bin文件夹:

      DotNetOpenAuth.AspNet.dll
      DotNetOpenAuth.Core.dll
      DotNetOpenAuth.OAuth.Consumer.dll
      DotNetOpenAuth.OAuth.dll
      DotNetOpenAuth.OpenId.dll
      DotNetOpenAuth.OpenId.RelyingParty.dll
      

      如果您不需要它们,请从名为“DotNetOpenAuth.Core”等的配置中删除 dependentAssemblies

      【讨论】:

      • 所有这些dll文件都存在于bin文件夹中。
      • 检查配置中的依赖组件
      【解决方案6】:

      试试这个:

      • 编辑 PublishProfiles 文件夹中的 *.pubxml 文件
      • 设置 DeleteExistingFiles true
      • 更新所有 nugget 包,重新构建、重新发布和瞧,问题已解决!

      ...当我遇到同样的问题时为我工作。

      【讨论】:

        【解决方案7】:

        检查是否有任何项目正在使用/引用具有 HRESULT: 0x80131040 错误的项目。如果是,请检查这些项目是否有类似的 .dll 被引用并且版本是否相同。如果它们的版本号不同,则导致上述错误。

        【讨论】:

          【解决方案8】:

          我对异常-from-hresult-0x80131040 的 itextsharp 和 itextsharp.xmlworker dll 有问题,所以我从引用中删除了这两个 dll,并直接从 nuget 包下载了新的 dll,这解决了我的问题。

          这种方法可能有助于解决其他人的问题。

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2012-08-19
            • 2012-02-26
            • 1970-01-01
            • 2011-03-01
            相关资源
            最近更新 更多