NuGet 更新后出现的 FileLoadException

5

在更新了所有NuGet软件包后,我的一个应用程序在启动时出现了FileLoadException崩溃:

Could not load file or assembly 'Microsoft.Practices.ServiceLocation, Version=1.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies.

在将ServiceLocation升级到1.3.0.0版本后,我仔细检查了所有程序集以确保它们都使用该版本。然后我运行了Fuslogvw来诊断仍在引用旧版本的程序集:

LOG: DisplayName = Microsoft.Practices.ServiceLocation, Version=1.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
(Fully-specified)
LOG: Appbase = file:///C:/Users/Charlie/AppData/Local/Programs/MyClient/
LOG: Initial PrivatePath = NULL
LOG: Dynamic Base = NULL
LOG: Cache Base = NULL
LOG: AppName = MyClient.exe
Calling assembly : Microsoft.Practices.Prism.UnityExtensions, Version=5.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35.
===

因此,UnityExtensions(另一个NuGet软件包)仍在引用旧版本。但这应该没问题,因为我已经在我的app.config文件中添加了bindingRedirect

<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
  <dependentAssembly>
    <assemblyIdentity name="Microsoft.Practices.ServiceLocation" publicKeyToken="31bf3856ad364e35" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-1.2.0.0" newVersion="1.3.0.0" />
  </dependentAssembly>
</assemblyBinding>

但这似乎没有任何区别。我的应用程序是定位于.NET Framework 4.5.1的,并且我已经尝试了开启和关闭AutoGenerateBindingRedirects选项。换句话说,我尝试了所有方法。这里出了什么问题?


3
你是否使用了NuGet内置的工具来执行BindingRedirects?根据我的经验,手动操作容易出错:http://www.michael-whelan.net/nuget-add-bindingredirect/ - JohnD
我最终不得不重新做所有的包引用,一个接一个地,并有意将它们降级到ServiceLocation的1.2版本。 :( - Charlie
1
你在Fuslogvw.exe跟踪中恰好在关键时刻中断了它,此时它正要报告正在使用的配置。请发布完整的跟踪记录。 - Hans Passant
可能有一个原因可以将“UseSpecificVersion”设置为false。无论如何,由于大多数被引用的dll都是本地引用而不是来自GAC,建议从引用名称中删除版本和公钥信息。 - Vignesh.N
我曾经遇到过同样的问题,只需删除绑定重定向即可解决。 - kha
显示剩余2条评论
4个回答

1
你尝试过将绑定重定向更改为这样吗:
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
    <dependentAssembly>
        <assemblyIdentity name="Microsoft.Practices.ServiceLocation" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-1.3.0.0" newVersion="1.3.0.0" />
    </dependentAssembly>
</assemblyBinding>

请注意,我只将旧版本的上限从1.2.0.0更改为1.3.0.0,以捕获任何版本达到1.3并重定向它。

1
这不是你的示例中提供的内容,但它可能会帮助像我这样来到这里的其他人。
确保您没有设置错误的.NET版本。
例如,当使用.NET 4+时,“appliesTo =“v2.0.50727””将无法工作。
<assemblyBinding appliesTo="v2.0.50727" xmlns="urn:schemas-microsoft-com:asm.v1">
    <dependentAssembly>
        <assemblyIdentity name="Microsoft.Practices.ServiceLocation" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-1.3.0.0" newVersion="1.3.0.0" />
    </dependentAssembly>
</assemblyBinding>

1
你需要解决此问题的唯一方法是更新所有项目中与PRISM和Unity相关的软件包。无需编辑绑定重定向。
请参阅codeplex上的详细信息。

1
确保您配置文件中的引用实际上使用了正确的版本。它们可能与NuGet安装的版本不同步。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接