Maysam
Maysam

Reputation: 7367

Using C# class in VB.NET website

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

Upvotes: 0

Views: 315

Answers (2)

Maysam
Maysam

Reputation: 7367

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

Upvotes: 0

Kratz
Kratz

Reputation: 4330

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.

Upvotes: 3

Related Questions