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,062 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 74

Expert Comment

by:käµfm³d 👽
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
You should either have them all set to "Any CPU", or have them all set to "x86".
0
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
LVL 1

Author Comment

by:countrymeister
Comment Utility
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
Comment Utility
Since your Platform is "Active (x86)" then Platform Target should be "x86".
0
 
LVL 74

Expert Comment

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

Author Comment

by:countrymeister
Comment Utility
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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

763 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

12 Experts available now in Live!

Get 1:1 Help Now