【发布时间】:2025-12-17 20:35:01
【问题描述】:
我正在使用 asp.net 4.0 开发基于 Web 的应用程序。
我在 GAC 中使用了一些 dll,它们对旧的 dll 有一些嵌入式依赖项。
我已经配置了程序集,以便依赖项重定向到我机器上正确版本的 dll。这在 3.5 或更低版本的应用程序中完美运行,但是,当我尝试基于相同的 dll 构建 asp.net 4.0 应用程序时,它会出现如下错误:
Could not load file or assembly 'ControlReferencedByMyDll, Version=2.0.0.0,
Culture=neutral, PublicKeyToken=XXXXXXXXXXXXXXXX' or one of its dependencies.
The located assembly's manifest definition does not match the assembly reference.
(Exception from HRESULT: 0x80131040)
我的 ControlReferencedByMyDll 版本是 2.0.1.0。
我找不到 .net 4.0 的 GAC 配置实用程序,但在我的 machine.config(在 .net 4.0 的 Framework 和 Framework64 文件夹中)我添加了类似的内容:
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="ControlReferencedByMyDll" PublicKeyToken="XXXXXXXXXXXXXXXX"/>
<bindingRedirect oldVersion="1.0.0.0-9.9.9.9" newVersion="2.0.1.0"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
看看这是否是问题所在。
我什至尝试将 applyTo="v2.0.50727" 属性添加到 assemblyBinding 以查看它是否有所作为。
但好像没有。
还有其他人遇到过这个问题吗?更重要的是,谁能帮我解决这个问题?
【问题讨论】:
-
好的,我发现了一些似乎可行的方法,尽管如果存在更好的答案,我仍然有兴趣看到更好的答案,也许有人可以告诉我为什么这样做。我只是将上面显示的代码直接放入我的 web.config 中,一切都很好。
标签: asp.net .net-4.0 asp.net-4.0 gac