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

附加信息:无法加载 文件或程序集 “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相反的参考。

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


当前回答

你说你的解决方案中有很多项目……好吧,从接近构建顺序顶部的一个开始。建立一个,一旦你找到它,你可以应用相同的修复其余的。

老实说,你可能只需要更新一下你的推荐信。这听起来像是您更新了版本而没有更新引用,或者如果您将解决方案保留在源代码控制中,这是一个相对路径问题。只需验证您的假设,并重新添加参考。

其他回答

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之间有什么区别?

尝试检查引用的“Copy to Local”属性是否设置为true,并且特定版本是否设置为true。这与Visual Studio中的应用程序相关。

微软企业库(由. 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更新到最新版本。

在我的情况下,bin文件夹是一个名为Unity的非引用dll。MVC3,我试图在visual studio中搜索任何参考,没有成功,所以我的解决方案很简单,从bin文件夹中删除那个dll。

清理解决方案,然后右键单击项目并选择Package

在这里增加程序集和程序集文件版本并重新构建。

如果这行不通,

1 -在文件资源管理器中打开解决方案。

2 -关闭Visual Studio。

3 -删除所有bin和obj文件夹。

4 -重新打开项目并构建它。