如何使程序集重定向工作在.NET 4.0中的Web应用程序应用程序、重定向、程序、工作

2023-09-07 16:32:36 作者:櫻花落″舞一世傾城

我正在使用asp.net 4.0基于Web的应用程序。

I am working on a web-based application using asp.net 4.0.

我有一些dll文件,我使用的GAC有一些嵌入式的依赖在旧的DLL。

I have some dlls I am using in the GAC that have some embedded dependencies on older dlls.

我已经配置的组件,使依赖重定向到该DLL的我的机器上正确的版本。这工作完全在3.5或更低版本的应用程序,但是,当我尝试基于相同的dll建立一个asp.net 4.0应用程序,它就像一个错误扼流圈:

I have Configured the assemblies so that the dependency redirects to the correct version of the dll on my machine. This works perfectly in a 3.5 or lower version application, however, when I try to build an asp.net 4.0 application based on the same dlls, it chokes with an error like:

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版本。

where my version of ControlReferencedByMyDll is version 2.0.1.0.

我无法找到.NET 4.0的GAC配置实用程序,但在我的machine.config(在这两个框架和Framework64文件夹.NET 4.0),我已经加入这样的:

I could not find a GAC configuration utility for .net 4.0, but in my machine.config (In both the Framework and Framework64 folders for .net 4.0) I have added something like:

<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>

要查看是否这是问题。

to see if that was the problem.

我甚至试过了appliesTo =V2.0.50727属性添加到assemblyBinding,看它是否发挥了作用。

I've even tried to add the appliesTo="v2.0.50727" attribute to the assemblyBinding to see if it made a difference.

但它似乎并不具备。

任何人都有这个问题吗?更重要的是,任何人都可以帮我解决这个问题?

Has anyone else had this problem? and more importantly, can anyone help me solve this?

推荐答案

好了,我还没有看到任何额外的反馈意见,在这一点上,我还没有决定,如果/所在的config文件被机器之间的覆盖。配置和web.config文件,但这是什么工作。

Okay, I haven't seen any additional feedback, and at this point, I have not determined if/where the .config file is being overridden between machine.config and web.config, but this is what works.

我添加code类似以下内容:

I add code similar to the following:

<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>

直接到我的web.config文件。

Directly to my web.config file.

我提出这是一个答案,我自己的问题,但如果你碰巧知道一个更好的办法,或者知道是什么引起的machine.config和web.config文件之间的脱节,请分享指示之前,

I am submitting this as an answer to my own question, but as indicated before, if you happen to know a better way, or know what's causing the disconnect between machine.config and web.config, please share.

感谢您