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

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

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


当前回答

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

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

其他回答

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

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

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

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

我有这个问题,这个错误其实很愚蠢。我为.dll文件指定了错误的位置,在将位置更改为正确的位置后,加载发生了正确的情况(回答,所以其他人不要犯这个错误)。

TLDR; 我的解决方案是在visual studio中恢复默认设置。


我在visual studio 2019社区版上,我在不同的项目中遇到了同一个dll文件的问题,我没有接触过。

After trying out all the answers in this question (as of 2020-07-22 7:13UTC) I decided to repair visual studio installation (backed up my settings beforehand). After installation opened the solutions that had the problem and the problem was gone. After that imported my settings that and the problem came back!! So without repairing visual studio installation again (which takes a few minutes + one restart) I've simply restored VS default settings and then it works. If I end up having time to investigate, I'll edit the answer and pinpoint the underlaying issue

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