views:

26

answers:

2

Trying to setup my laptop to edit and run my C# application which called C++ dll. compile is ok, but when I run it, TypeInitializationException was unhandled error happened.

It said: The type initializer for '<Module>' threw an exception.

I also installed Visual Studio 2008 sp1.

No any problem at my desktop computer. Same OS, windows XP.

any idea?

A: 

In my experience this means that you are missing one of your libraries reference assemblies or Dlls or that a constructor of one of your objects threw an exception.

mjmarsh
A: 

Run the app under the debugger and take a look at the InnerException property - it should tell you what failed.

Alternatively, set up the debugger to break on every exception, instead of the default behaviour of only breaking on unhandled exceptions. It should take you to the line of code that fails.

If that doesn't help, and you built the C++ DLL yourself, turn on unmanaged debugging via the properties for the C# project. This will allow you to step into the C++ code and track down the original error.

Tim Robinson
InnerException says: The C++ module failed to load. Unable to load DLL MSVCR80.dll. how to fix it?
5YrsLaterDBA
Sounds like you need to deploy MSVCR80.DLL. This will already be installed on your development machine but it won't be on machines that don't have VS2008 installed. Read this article: http://support.microsoft.com/kb/326922
Tim Robinson