exceptionerror
exceptionerror

Reputation: 81

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. However, I quickly get a cascade of BadImageFormat exceptions when NServiceBus tries to scan for assemblies. 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.

The cleanest solution I could come up with was to use corflags.exe to modify the third party assembly to be AnyCPU. This way I don't have to modify any of the many other referenced libraries to be 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.

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?

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; 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. Is this the case?

Per comment questions: The third party library references (I know this from decompiling the third party library.)

and the Version for all is 4.0.0.0.

Upvotes: 1

Views: 447

Answers (1)

usr
usr

Reputation: 171206

The .NET Framework will just work regardless of what bitness a .NET process uses. The C# compiler does not care about bitness. All it does is set PE flags which can be changed.

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);. That's all.

I was warned that in general converting an x86 to x64 assembly with corflags could cause problems.

True.

The System.Collections assembly was an example.

Not sure where that is coming from... False.

Upvotes: 1

Related Questions