Solved

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

Posted on 2014-04-29
8
5,425 Views
Last Modified: 2014-04-29
System.BadImageFormatException: Could not load file or assemblyor one of its dependencies. An attempt was made to load a program with an incorrect format.

I havea 64 bit OS, I have a dll that I am building for ANy CPU /ANy CPU. This dll has a few other dll's
Not sure which dll is causing this issue
0
Comment
Question by:countrymeister
  • 3
  • 3
  • 2
8 Comments
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 40029430
The exception should tell you which is the offending assembly. Check to make sure that one was compiled as Any CPU (or x64).
0
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 40029469
If you are including that DLL in another project then it needs to be compiled for the same target as the app which will use it.

So, if the app using it is 32-bit, you need to build for 32-bit.
0
 
LVL 1

Author Comment

by:countrymeister
ID: 40029498
Kaufmed and Carl

I have three projects in my solution.
Project A is the windows service (has reference to B)
Project B is a Wcf service hosted in the windows service (has  a reference to C)
Project C is the class library which is referenced in B

Project A is built a Platform x86 , target platform x64
Project B built for any CPU, target platform AnyCPU
Project C built for any cpu , target platform  any cpu
0
How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

 
LVL 52

Accepted Solution

by:
Carl Tawn earned 500 total points
ID: 40029534
You should either have them all set to "Any CPU", or have them all set to "x86".
0
 
LVL 1

Author Comment

by:countrymeister
ID: 40029590
I have tried doing that, There are two settings on the build configuration.
Can you let me know what they should be for project A , B and C

I have attached a screen shot
Target.png
0
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 40029602
Since your Platform is "Active (x86)" then Platform Target should be "x86".
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 40029607
Which assembly does the exception reference?
0
 
LVL 1

Author Comment

by:countrymeister
ID: 40029993
I got pass ed those errors now, by setting the both the targets to x86.
Now I get an error in installutil.exe
Exception ocurred while initializing the installation
System.IO.FileNotFoundException . Could not load file or assembly  or one of its dependencies.

I tried using the proper installutil.exe from
C:\Windows\Microsoft.NET\Framework\v4.0.30319
0

Featured Post

How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

792 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question