从.NET v4.0的组件链接到一个.net 2.0组件也出现链接(和别名)的mscorlib V2.0。为什么?组件、链接、别名、NET

2023-09-05 02:06:28 作者:无人伴我°终老

我有一个.NET程序集进口对V2.0运行时链接程序集。我遇到的问题是,当我尝试在我的程序集运行一些测试,融合改掉加载错误版本的依赖程序集的。

I have a .Net assembly which imports an assembly linked against the v2.0 runtime. The problem I'm having is that when I try to run some tests on my assembly, Fusion trys to load the wrong version of a dependent assembly.

在看程序集清单,我可以看到为什么:错版 FSharp.Core 的链接。在我的构建文件,我让 FSharp.Core,版本= 4.0.0.0 明确,但 FSharpPowerPack 出现链接到V2.0.0.0,以及一些如何,似乎双赢这个链接的战斗。

After looking at the assembly manifest, I can see why: the wrong version of FSharp.Core is linked. In my build file, I make FSharp.Core, Version=4.0.0.0 explicit, but FSharpPowerPack appears to link to v2.0.0.0, and some how seems to "win" this linking battle.

下面的清单:

// Metadata version: v4.0.30319
.assembly extern mscorlib
{
  .publickeytoken = (B7 7A 5C 56 19 34 E0 89 )                         // .z\V.4..
  .ver 4:0:0:0
}
.assembly extern System.Core
{
  .publickeytoken = (B7 7A 5C 56 19 34 E0 89 )                         // .z\V.4..
  .ver 4:0:0:0
}
.assembly extern System
{
  .publickeytoken = (B7 7A 5C 56 19 34 E0 89 )                         // .z\V.4..
  .ver 4:0:0:0
}
.assembly extern FSharp.PowerPack
{
  .publickeytoken = (A1 90 89 B1 C7 4D 08 09 )                         // .....M..
  .ver 2:0:0:0
}
.assembly extern mscorlib as mscorlib_8
{
  .publickeytoken = (B7 7A 5C 56 19 34 E0 89 )                         // .z\V.4..
  .ver 2:0:0:0
}
.assembly extern System.Core as System.Core_9
{
  .publickeytoken = (B7 7A 5C 56 19 34 E0 89 )                         // .z\V.4..
  .ver 3:5:0:0
}
.assembly extern FSharp.Core
{
  .publickeytoken = (B0 3F 5F 7F 11 D5 0A 3A )                         // .?_....:
  .ver 2:0:0:0
}

请注意,它似乎在包括 FSharpPowerPack 的v2.0和其它.NET程序集(mscorlib程序,系统,System.Core程序)V3.5包括和别名。为什么会出现这种情况?难道这涉及到装错版 FSharp.Core

Note that it seems that by including FSharpPowerPack the v2.0 and v3.5 of other .Net assemblies (mscorlib, System, System.Core) are included and aliased. Why does this happen? Is this related to the issue of loading the wrong version of FSharp.Core?

编辑:要澄清,正在由C#4.0版编译器生成我的组装

To clarify, my assembly is being generated by the C# v4.0 compiler.

推荐答案

您在其中将加载编译的程序集的应用程序的控制权?如果是这样,您可以使用绑定重定向在你的app.config文件强制所有FSharp.Core参考使用4.0版本:

Are you in control of the application which will load the compiled assembly? If so, you could use a binding redirect in your app.config file to force all FSharp.Core references to use version 4.0:

<configuration>
    <runtime>
        <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
            <dependentAssembly>
                <assemblyIdentity name="FSharp.Core" publicKeyToken="b03f5f7f11d50a3a" culture="neutral"/>
                <bindingRedirect oldVersion="0.0.0.0-99.9.9.9" newVersion="4.0.0.0"/>
            </dependentAssembly>
        </assemblyBinding>
    </runtime>
</configuration>

如果您在使用自动测试应用程序的问题,您可能能够编辑它的配置文件以类似的方式,假设它不会影响运行。

If you are having the problem with an automated test application, you might be able to edit its config file in a similar way, assuming it doesn't affect its operation.

 
精彩推荐
图片推荐