简体   繁体   English

从.Net v4.0程序集链接到.Net v2.0程序集也似乎链接(和别名)mscorlib v2.0。 为什么?

[英]Linking to a .Net v2.0 assembly from a .Net v4.0 assembly also appears to link (and alias) mscorlib v2.0. Why?

I have a .Net assembly which imports an assembly linked against the v2.0 runtime. 我有一个.Net程序集,它导入了与v2.0运行时链接的程序集。 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. 我遇到的问题是,当我尝试在程序集上运行一些测试时,Fusion尝试加载错误版本的从属程序集。

After looking at the assembly manifest, I can see why: the wrong version of FSharp.Core is linked. 查看程序集清单后,我可以看到原因:链接了错误版本的FSharp.Core 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. 在我的构建文件中,我明确显示了FSharp.Core, Version=4.0.0.0 ,但FSharpPowerPack似乎链接到v2.0.0.0,并且有些人似乎“赢得”了这场链接之战。

Here's the manifest: 这是清单:

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

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. 请注意,似乎通过包含FSharpPowerPack ,其他.Net程序集(mscorlib,System,System.Core)的v2.0和v3.5也包括在内并具有别名。 Why does this happen? 为什么会这样? Is this related to the issue of loading the wrong version of FSharp.Core ? 这是否与加载错误版本的FSharp.Core

Edit: To clarify, my assembly is being generated by the C# v4.0 compiler. 编辑:澄清一下,我的程序集是由C#v4.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: 如果是这样,则可以在app.config文件中使用绑定重定向来强制所有FSharp.Core引用使用版本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. 如果您在自动化测试应用程序方面遇到问题,则可以假定它不影响其操作,并且可以通过类似的方式编辑其配置文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何说服sql server 2008r2使用clr v4.0而不是v2.0? - How to convince sql server 2008r2 to use clr v4.0 instead of v2.0? 调试时,托管旧版(v3.5,v3.0,v2.0)和托管旧版(v4.5,v4.0)的默认设置在哪里? - Where is the default setting for Managed Legacy (v3.5, v3.0, v2.0) vs Managed Legacy (v4.5, v4.0) when debugging? 在Windows 8 RTM上的.NET应用程序中嵌入Powershell v2.0 - Embedding Powershell v2.0 in .NET app on Windows 8 RTM 什么是ASP .NET Apps v2.0 *的WMI类? - What is the WMI class for ASP .NET Apps v2.0*? 从IIS6 .net 2.0(win2k3)迁移到IIS7.5 .net 4.0(win2k8)-&gt;如何处理web.config程序集V = 2.0.0.0 - Moving from IIS6 .net 2.0 (win2k3) to IIS7.5 .net 4.0 (win2k8) --> how to handle web.config assembly V=2.0.0.0 如何在.NET 4.0解决方案中链接.NET 2.0程序集 - How to link a .NET 2.0 assembly in a .NET 4.0 solution 如何在没有.NET v4.0的目标环境上部署.NET v4.0应用程序? - How can I deploy .NET v4.0 application on target environment without .NET v4.0? 在4.0 .NET Runtime上加载2.0 .NET程序集 - Loading 2.0 .NET assembly on 4.0 .NET Runtime 使用运行时4.0的v2.0目录中的程序集 - Assemblies in v2.0 directory which using runtime 4.0 CSharpCodeProvider从.NET 4.0应用程序输出.NET 2.0程序集 - CSharpCodeProvider output .NET 2.0 assembly from .NET 4.0 application
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM