0

I've a C# class with CorePoll namespace, I compiled it to .DLL file and put it inside bin folder of website. But I cannot use it. Imports CorePoll returns Could not load file or assembly 'CorePoll' or one of its dependencies. An attempt was made to load a program with an incorrect format. It's my class file in C# http://pastebin.com/JkdrnXyT
enter image description here

11
  • What does the library depend on? If it depends on other dlls, you need to place them too in the in bin directory. Commented Dec 12, 2012 at 13:02
  • I do not have additional dlls, I created an empty class then paste this code into the .cs file Commented Dec 12, 2012 at 13:03
  • When version of .NET did you compile the C# class with? Is it the same version the site runs under? Commented Dec 12, 2012 at 13:04
  • 3
    make sure there aren't any differences in platform and/or .Net version when building. Both should point to the same target platform (x86, x64, ...). Check the C# code first and make sure your VB uses the same build settings. Commented Dec 12, 2012 at 13:07
  • If the classes in the CorePoll namespace have references to external assemblies (3rd party libraries, libraries you've written, etc.) you will need to put those assemblies (dlls) in the bin directory as well as the dll that you compiled. Commented Dec 12, 2012 at 13:34

2 Answers 2

3

The message An attempt was made to load a program with an incorrect format., typically comes from mixing 64/32 bit environments. When you build your .DLL, make sure to select Any CPU as the Target CPU int the build settings. That way, the DLL should work no matter if the website is running 32 or 64 bit. But be aware, the message also states Could not load file or assembly 'CorePoll' or one of its dependencies., meaning that if you've referenced other libraries in your DLL, they could be failing to load as well.

Edit: After looking at the documentation, another potential cause of this exception is mixing projects built with different versions of the .Net Framework. Is this possibly causing your error?

Components have been created using different versions of the .NET Framework. Typically, this exception occurs when an application or component that was developed using the .NET Framework 1.0 or the .NET Framework 1.1 attempts to load an assembly that was developed using the .NET Framework 2.0 SP1 or later, or when an application that was developed using the .NET Framework 2.0 SP1 or .NET Framework 3.5 attempts to load an assembly that was developed using the .NET Framework 4. The BadImageFormatException may be reported as a compile-time error, or the exception may be thrown at run time.

Sign up to request clarification or add additional context in comments.

4 Comments

I've set Any CPU and I have no 3rd party libraries, but it still does not work. Uploading the solution files will help you?
The only thing I've ever seen cause that error message is the 32/64 bit thing. The only other thing is if the file is somehow being corrupted when you upload it to the website, but that is doubtful.
Both projects are set to Any CPU and both are running in the localhost
I looked at the documentation for BadImageFormatException and it seems like there are a couple other potential causes. See my edit.
0

None of answers helped me, I converted the C# code to VB.NET and used it with no problem, thanks for your time.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.