简体   繁体   English

x86和x64 .NET Framework库的IL是否有区别?

[英]Is there any difference in the IL of x86 vs x64 .NET Framework libraries?

Here is the exact scenario. 这是确切的情况。 I have an x86 assembly from a third party vendor I'd like to use with NServiceBus. 我有一个想与NServiceBus一起使用的第三方供应商提供的x86组件。 However, I quickly get a cascade of BadImageFormat exceptions when NServiceBus tries to scan for assemblies. 但是,当NServiceBus尝试扫描程序集时,我很快会收到一系列BadImageFormat异常。 That's something I can fix by using the x86 version of NServiceBus, but then I have to change all of my other referenced libraries to do the same, some which depend on x64 assemblies. 我可以使用x86版本的NServiceBus来解决此问题,但是随后我必须更改所有其他引用的库以执行相同的操作,其中某些依赖于x64程序集。

The cleanest solution I could come up with was to use corflags.exe to modify the third party assembly to be AnyCPU. 我能想到的最干净的解决方案是使用corflags.exe将第三方程序集修改为AnyCPU。 This way I don't have to modify any of the many other referenced libraries to be x86. 这样,我不必将许多其他引用的库修改为x86。 So far, this is working perfectly. 到目前为止,这一切正常。

However, I've been warned that this could be a problem if the third party library makes references to any libraries that have a different implementation in x86 vs x64. 但是,我已经警告过,如果第三方库引用在x86与x64中具有不同实现的任何库,则可能会出现问题。

So my question is, is there any difference in the IL of x86 and x64 .NET Framework Libraries, for example, is the IL of System.* x64 equal to the IL of System.* x86? 所以我的问题是,x86和x64 .NET Framework库的IL是否存在任何差异,例如System。* x64的IL是否等于System。* x86的IL?

To the best of my understanding the platform target is simply a preference set by the developer, and does not affect the actual resulting IL; 据我所知,平台目标只是开发人员设置的首选项,并不影响实际产生的IL; my solution to convert the third party assembly with corflags.exe should be safe as long as the .NET Framework also uses the same IL in its x64 and x86 assemblies. 只要.NET Framework在其x64和x86程序集中也使用相同的IL,我用corflags.exe转换第三方程序集的解决方案应该是安全的。 Is this the case? 是这样吗

Per comment questions: The third party library references (I know this from decompiling the third party library.) 每个注释的问题:第三方库引用(我从反编译第三方库中知道这一点。)

  • System 系统
  • System.Runtime.Serialization System.Runtime.Serialization
  • System.Runtime.Serialization System.Runtime.Serialization
  • mscorlib mscorlib程序
  • (their dependencies) (它们的依赖项)

and the Version for all is 4.0.0.0. 所有版本均为4.0.0.0。

The .NET Framework will just work regardless of what bitness a .NET process uses. 不管.NET进程使用什么位数,.NET Framework都将起作用。 The C# compiler does not care about bitness. C#编译器不关心位。 All it does is set PE flags which can be changed. 它所做的只是设置可以更改的PE标志。

Clearly, the 3rd party lib you want to modify might depend on the bitness by referencing libraries with fixed bitness or by simply containing Debug.Assert(IntPtr.Size == 4); 显然,要修改的第三方库可能取决于位数,方法是引用固定Debug.Assert(IntPtr.Size == 4);库,或者仅包含Debug.Assert(IntPtr.Size == 4); . That's all. 就这样。

I was warned that in general converting an x86 to x64 assembly with corflags could cause problems. 有人警告我,通常将带有corflag的x86转换为x64程序集可能会引起问题。

True. 真正。

The System.Collections assembly was an example. System.Collections程序集就是一个示例。

Not sure where that is coming from... False. 不知道那是哪里来的...错误。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM