문제

I have a language compiler that I've just updated to target .NET 4.0 and the metadata generator for framework assemblies now fails on System.Data.dll, while all others work fine (mscorlib, System, etc.)

The metadata generator simply loads assemblies, reflects over all the types and memberinfo and generates a stub class for the language.

I'm using Assembly.Load() and/or Assembly.ReflectionOnlyLoad()

Could not load file or assembly 'file:///c:\windows\Microsoft.NET\framework\v4.0.30319\System.Data.dll' or one of its dependencies. An attempt was made to load a program with an incorrect format.

It is built for "AnyCPU". I'm running Windows 7/x64 with .NET 4.5 update installed.

도움이 되었습니까?

해결책

If you use corflags tool to analyze the assemblies, you should see that ILONLY: 0 for System.Data.dll while the others (mscorlib, System) ILONLY: 1. More information regarding ILONLY can be found at here.

Thus, the assemblies were built differently and you should not expect reflection to work for all. System.Data.dll seems to be a mixed-mode assembly, which is always bitness dependent.

If you cannot run your app as 32 bit so as to load the 32 bit assemblies, you might consider Mono.Cecil as @xmojmr said, as it supports reading mixed-mode assemblies.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top