Visakh V A
Visakh V A

Reputation: 320

BadImageFormatException or TypeInitializationException when using VC++ dlls in a MVC application

I have a MVC application, which is referring another project (B) which is a x86 project has one Vc++ dll reference.

When I am trying to run the B project as a console application as start up project it is properly running.

But when I am accessing the same from MVC application , Am getting BadImageFormatException or TypeInitializationException.

I used Assembly trace and am getting exceptions as bellow from each place one by one

BinaryAssemblyInfo Exception thrown: 'System.Runtime.Serialization.SerializationException' in mscorlib.dll

Additional information: Unable to find assembly 'NI.Framework.Logger, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b98c50443551b471'.

RealProxy.cs

'System.Runtime.Serialization.SerializationException' in mscorlib.dll

Additional information: Unable to find assembly 'NI.Framework.Logger, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b98c50443551b471'.

Exception thrown: '.ModuleLoadException' in MsgComWrapper_4.0.dll Additional information: The C++ module failed to load while attempting to initialize the default appdomain.

Action method dispatcher.cs: Exception thrown: 'System.TypeInitializationException' in System.Web.Mvc.dll

Additional information: The type initializer for '' threw an exception.

AsyncControllerActionInvokers.cs

Exception thrown: 'System.TypeInitializationException' in System.Web.Mvc.dll

Additional information: The type initializer for '' threw an exception.

I have tried many trail and error but not worked.

Upvotes: 0

Views: 582

Answers (1)

Yuval Perelman
Yuval Perelman

Reputation: 4819

Well, AFAIK you have 2 options:

1. You can build your mvc app to x86. It will work on x64, it just will not use all the power x64 architecture can offer.

2. You can run your app on a x86 machine. That would also work

The only way to have a "true" AnyCpu app is to have all your dlls built for AnyCpu. Its very annoying and not intuitive and I have suffered a lot over this over time, but this is the reality. I'm still sure there is a better solution that I don't know of, even though I have spent a decent amount of time looking for it and found nothing

Upvotes: 0

Related Questions