System.BadImageFormatException.. What is the problem?

  • Thread starter Thread starter Madhu Gopinathan
  • Start date Start date
M

Madhu Gopinathan

Hi,
I am facing a problem in .NET COM InterOp. I have a COM Dll which I want to use from my CSharp code. So, I import the TLB directly from the DLL using the tlbimp tool to a managed DLL. I add a reference to this managed DLL in my CSharp solution. Now, when I try to create a new instance of an object inherent in the COM DLL using

MyObject object = new MyObject();

I recieve the error,

An unhandled exception of type 'System.BadImageFormatException' occurred in TestInterOp.exe.
Additional information: Exception from HRESULT: 0x800700C1.

What is the problem here? I have added the managed assembly to the GAC because I don't want to do that.

Regards,
Madhu.
 
Did you sign the assembly with a strong name?
Hi,
I am facing a problem in .NET COM InterOp. I have a COM Dll which I want to use from my CSharp code. So, I import the TLB directly from the DLL using the tlbimp tool to a managed DLL. I add a reference to this managed DLL in my CSharp solution. Now, when I try to create a new instance of an object inherent in the COM DLL using

MyObject object = new MyObject();

I recieve the error,

An unhandled exception of type 'System.BadImageFormatException' occurred in TestInterOp.exe.
Additional information: Exception from HRESULT: 0x800700C1.

What is the problem here? I have added the managed assembly to the GAC because I don't want to do that.

Regards,
Madhu.
 
Hi Dave,
Yes, I tried signing the assembly with a strong name as well. Still the error persisted. The code works if I add a reference to the COM DLL directly without having to go through the assembly.

Regards,
Madhu
 
You might try looking in the fusion log to see if the clr had trouble locating the assembly. Perhaps the reported exception isn't the true source of the problem.
Hi Dave,
Yes, I tried signing the assembly with a strong name as well. Still the error persisted. The code works if I add a reference to the COM DLL directly without having to go through the assembly.

Regards,
Madhu
 
Back
Top