Question

I have a web service that throws a BadImageFormatException any time I try to run the service from Visual Studio. This answer to another question suggested running peverify against DLLs to see if there are any problems. While my web service's DLL is fine, the web service depends on an ILMerged assembly, which does have errors:

[IL]: Error: [C:\blah\MyILMergedAssembly.dll : Encryption

Utils.SecureStringExtensions::SecureEquals][offset 0x00000055][found unmanaged pointer] [expected unmanaged pointer] Unexpected type on the stack.

[IL]: Error: [C:\blah\MyILMergedAssembly.dll : Encryption

Utils.SecureStringExtensions::SecureEquals][offset 0x0000005D][found unmanaged pointer][expected unmanaged pointer] Unexpected type on the stack.

[IL]: Error: [C:\blah\MyILMergedAssembly.dll : Encryption

Utils.SecureStringExtensions::SecureEquals][offset 0x0000007E] Unmanaged pointers are not a verifiable type.

3 Error(s) Verifying .\MyILMergedAssembly.dll

(188 Warnings)

I think these stem from my use of Marshal and IntPtr in MyILMergedAssembly, but everywhere I do that, I have the method declared as unsafe. How can I get rid of the errors peverify gives, and hopefully get rid of the BadImageFormatException that comes up when I try to run my web service?

Edit: it looks like maybe I can't use ILMerge to merge assemblies that have unsafe code. So I tried having my web service reference all the individual DLLs in MyILMergedAssembly, but I still get a BadImageFormatException. Now it gives me the exception on one of the individual assemblies. When I run peverify on that individual assembly, I get:

[IL]: Error: [C:\blah\Connection.dll : Connection

.ConnectionBase::.ctor] [HRESULT 0x80070002] - The system cannot find the file specified.

The ConnectionBase class to which it's referring is right there in Connection.dll, or at least it should be since the class is defined in the Connection namespace/project. Connection has 'Allow unsafe code' checked in its Build options. The constructor in ConnectionBase to which it might be referring is marked as internal.

Edit: I've tried checking 'Allow unsafe code' in the web service project that uses the DLLs with unsafe code. I also tried adding compilerOptions="/unsafe" to the Web.config file for the web service in the system.codedom > compilers > compiler node. I still get a page with the following when I run the web service, though:

Could not load file or assembly 'Connection' or one of its dependencies. An attempt was made to load a program with an incorrect format.

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top