Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4604816
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T00:20:52+00:00 2026-05-22T00:20:52+00:00

I have a web service that throws a BadImageFormatException any time I try to

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T00:20:52+00:00Added an answer on May 22, 2026 at 12:20 am

    Oh man, this is annoying. It wasn’t unsafe code, it wasn’t the 32/64-bit target platform settings on my projects in VS, it wasn’t ILMerge. I had to set the Enable 32-Bit Applications setting to True on the application pool in IIS 7 (I’m in Windows 7 64-bit). After restarting the app pool, my web service loads fine. Thanks to this blog for sending me in the right direction.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a web service that queries data from this json file, but I
I have a web-service that I will be deploying to dev, staging and production.
I have a web service that I created in C# and a test harness
I have a web service that uses Python's SimpleJSON to serialize JSON, and a
I have a web service that is protected by requiring the consuming third party
I have a web service that needs different settings for different environments (debug, test,
I have a web service that I can only hit if I'm logged into
Pretty simple scenario. I have a web service that receives a byte array that
We have a dotnet web service that a java using customer wants to connect
I have a web service class that the rest of the framework depends on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.