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,255 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
 
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
3 Use Cases for Connected Systems

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

 
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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.

863 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now