Clean a Visual Studio 2013 project? (System.BadImageFormatException: Could not load file or assembly)

I developed a solution using a Windows 7 32 bit machine. The thing is that now, I have to run it into a 64 bit windows 8 machine but I am having an error that I suspect it is because of the 32/64 bit thing: "System.BadImageFormatException: Could not load file or assembly".

Someone told me I should delete the temporary files for the solution because they were compiled in 32 bit way.

How can I clean the 32 bit libraries so when I click in "Compile" in my 64 bit version it re-creates the 64 bit versions of the files? Should I delete the \Bin folder? or what?
José PerezAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

It would certainly sound more like you are mixing 32bit and 64bit mode assemblies. Cleaning is not necessarily the solution (it will help a lot, but not on it's own).

Your own libraries: Are all your libraries targetting the same platform i.e. all 64bit or all 32bit or all AnyCPU? Try compiling everything to the same thing.
Referenced Assemblies: Are you using any unmanaged assemblies or 32bit assemblies? Libraries outside your control may sometimes impose limitations on the platforms that you can target. you might be forced to compile to 32bit only.
Jacques Bourgeois (James Burger)PresidentCommented:
There is a Clean Solution option in the Debug menu to delete the working files.

But I would advise against compiling for 64-bit. In order to do so, everything else that the application uses must be 64-bit. It is still hard to get an environment where everything is 64-bit, so you almost end up with your application not working on some computers.

The best bet is to compile for AnyCPU. When doing so, the JIT on the system will automatically adjust for what is available on that machine. If you happen to run on a computer where all the necessary components exist in 64-bit, the final compilation will be 64-bit. Otherwise, it will adjust so that the application run on that computer.
José PerezAuthor Commented:
ok but the thing is that I am developing in a windows 8.1 pro station but the system is a website for a Windows 2008 R2 64 bit version...

How should I compile for the website to work for Windows 2008 R2 64 bits?
Become a Microsoft Certified Solutions Expert

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

Jacques Bourgeois (James Burger)PresidentCommented:
The framework is the framework. Except for security and access right considerations, very basic considerations such as these are the same no matter the environment.

This being said, just make sure that you target the same version of the framework as the one installed on the computer where the application will be running.

You can define the target framework from the Application tab of the project's Properties window.
José PerezAuthor Commented:
I am using the same framework version, but the same error appears "System.BadImageFormatException", I have done everything :(
Jacques Bourgeois (James Burger)PresidentCommented:
The suggestion I gave you is the one I had to use a few times, and the one that is seen most often when someone has problems with that Exception. But there are other things to look for.

Give a look at this page from Microsoft. It states different situations where that Exception is triggered. One might correspond to your situation.
José PerezAuthor Commented:
It states "To address this exception, set the project's Platform target property to x86 (instead of x64 or AnyCPU) and recompile." This sounds like it could help me a lot but I'm affraid this will send me an error on the target host that is 64 bits. Please your comment.
Jacques Bourgeois (James Burger)PresidentCommented:
Once again, it depends on what is installed on the system.

This one is the first I got when I moved to 64-bits. I was using a few old Microsoft Access .mdb files. I eagerly switched all my projects to x64, and they eagerly all bombed on me, telling me that Access was not installed, while it was. The only way to get these applications working with a .mdb file, even on 64-bits computers, was to compile for x86.

Some of these applications are still running well, even on Windows 8.1 64-bits.

Even Microsoft suggest installing Microsoft Office 32-bits on 64-bits computers, so there is nothing wrong with that if your application cannot gain from 64-bits.

Any CPU is the way to go most of the time, but in some situations, specially if your application happens to use older COM dlls, forcing 32-bits might be required.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
José PerezAuthor Commented:
Many thanks, excellent comments and answer.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.