我有另一个这些“无法加载文件或程序集或其依赖项之一”的问题。

附加信息:无法加载 文件或程序集 “Microsoft.Practices.Unity, Version = 1.2.0.0、文化=中立, 都31 bf3856ad364e35”或 它的依赖项之一。在位于 程序集的显式定义可以 不匹配程序集引用。 (异常来自HRESULT: 0x80131040)

我不知道是什么导致了这种情况,也不知道如何调试它来找到原因。

我在我的解决方案目录.csproj文件中做了一个搜索,我有Unity的每个地方:

参考 包括= " Microsoft.Practices.Unity, Version = 2.0.414.0、文化=中立, 都31 bf3856ad364e35, processorArchitecture = MSIL”

在我的任何项目中都找不到任何与1.2.0.0相反的参考。

我该怎么解决这个问题呢?


当前回答

微软企业库(由. nettiers引用)是我们的问题,它反过来引用了一个旧版本的Unity。为了解决这个问题,我们在web.config中使用了以下绑定重定向:

<configuration>
    <runtime>
        <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
            <dependentAssembly>
                <assemblyIdentity name="Microsoft.Practices.Unity" publicKeyToken="31bf3856ad364e35" culture="neutral" />
                <bindingRedirect oldVersion="1.0.0.0-2.0.414.0" newVersion="2.1.505.0" />
            </dependentAssembly>
            <dependentAssembly>
                <assemblyIdentity name="Microsoft.Practices.Unity.Configuration" publicKeyToken="31bf3856ad364e35" culture="neutral" />
                <bindingRedirect oldVersion="1.0.0.0-2.0.414.0" newVersion="2.1.505.0" />
            </dependentAssembly>
        </assemblyBinding>
    </runtime>
</configuration>

或者,您可能只想将Enterprise Library更新到最新版本。

其他回答

下面的方法对我很有效。

删除临时文件C:\Windows\Microsoft.NET\Framework\v4.0.30319\临时ASP. net网络文件 关闭VSTS,然后重新打开 删除和添加相同的dll(注意:您添加了相同的匹配版本)

检查你是否引用了一个程序集,而这个程序集又引用了一个旧版本的unity。例如,假设你有一个名为ServiceLocator.dll的程序集,它需要一个旧版本的Unity程序集,现在当你引用ServiceLocator时,你应该为它提供旧版本的Unity,这就产生了问题。 可能是所有项目构建其程序集的输出文件夹,有一个旧版本的unity。

你可以使用FusLogVw找出谁在加载旧的程序集,只需要为日志定义一个路径,并运行你的解决方案,然后检查(在FusLogVw中)Unity程序集加载的第一行,双击它并查看调用程序集,然后就可以了。

Juntos的答案是正确的,但你也应该考虑:

对于unity v2.1.505.2,不同的AssemblyVersion和AssemblyFileVersion属性被指定:

AssemblyFileVersion被NuGet使用,但是CLR并不关心它! CLR将只使用AssemblyVersion!

因此,您的重定向应该应用于在AssemblyVersion属性中指定的版本。因此应该使用2.1.505.0

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

参见: AssemblyVersion, AssemblyFileVersion和AssemblyInformationalVersion之间有什么区别?

我也得到了这个可怕的错误,并找到了一个解决方案…

右键单击解决方案名称 点击清洁溶液 重启Visual Studio 去项目属性>>构建 将配置更改为发布 开始调试(F5)

1), 2)

4), 5)

希望这也能帮助到你。

我一直在visual studio 2015的web表单项目上得到这个错误。我关闭了VisualStudio,我杀死了ScriptedSandbox64.exe, Microsoft.VsHub.Server.HttpHostx64.exe, Microsoft.VsHub.Server.HttpHostx.exe *32, Microsoft.VisualStudio.Web.Host.exe *32进程,它似乎有助于解决问题。