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

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

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


当前回答

检查Web.config/App。配置文件在您的项目。查看版本号是否正确。

<bindingRedirect oldVersion="X.X.X.X-X.X.X.X" newVersion="X.X.X.X" />

这对我很管用。

其他回答

对我来说,在没有unity c# Projects Checkmark的情况下重建unity游戏是可行的。

如果你在Windows xp上打开一个应用程序时得到这个错误消息,这意味着你首先安装了这个应用程序,因为它不能在没有net framework 4和service pack 3的情况下工作。你安装了两者,再次得到这个错误,所以你应该重新安装该应用程序,但首先从添加和删除卸载

如果这不是工作,请不要虐待我。我也是一名大三学生

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。

我想这会迫使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更新到最新版本。