Tags: alli, application, build, bunch, debug, excpetion, initializer, ltmodulegt, microsoft, mode, msdn, net, projects, release, software, solution, threw, type, visual, working
the type initializer for <Module> threw an excpetion ...?
I have .Net solution with bunch of c++ and c# projects with .In Debug mode the application is working fine.When I build the solution in release mode and try to run the application I am getting the strange error "The the type initializer for <Module> threw an excpetion The C++ Module failed to load during native initialization".The problem with it is not throwing any error in debug mode,It was happening only in release mode,Can any aware of this problem?
Leave a comment...
- 5 Comments
- Sounds like your release build isn't copying all the files it needs to run. Verify that all the binaries that are needed are in the appropriate directory. The output directory for debug is different than for release.
Hope this helps,
Michael Taylor - 11/23/05#1; Tue, 02 Oct 2007 17:54:00 GMT
I'm having the same problem; I don't have any files present in the Debug directory that aren't present in the Release directory.
Any other ideas?
I see this post is a year old; when searching on Google for this error message, oddly enough, this is the only thread/page I found mentioning the error.
Appreciate any help you can provide.
Thanks!#2; Tue, 02 Oct 2007 17:55:00 GMT
I add myself to the list of folks having this strange problem. I have a C# application that calls unmanaged code via a managed C++ wrapper class, and my Release version is throwing this exception. It happens upon calling the constructor of the C# class that, in its constructor, initializes the C++ wrapper class.
I'll add that I did see this error in my Debug build, as well -- though it seems to have gone away now, after a bunch of rebuilding.
Mike#3; Tue, 02 Oct 2007 17:56:00 GMT
I had a similar problem and I also found this forum to be the only place that this problem was even mentioned. I found out the there seems to be a problem with VS.NET 2005 SP1. I did the following:
(1) I have a simple MFC dialog application that was created with an earlier version of Visual Studio. So it doesn't even have unicode support. This application was already converted to VS.NET 2005 and worked fine.
(2) I decided to migrate this application to the .NET platform by activating the /clr compiler switch. This also worked fine.
(3) Later I created a .NET user control by using the wizards. This control accesses a COM component. The language used was C++/CLI. For educational purposes I created the very same control using a C# project.
Both user controls worked perfectly when integrated into the MFC dialog application. I have placed a button into the dialog application. The user control is placed on a separate dialog that is opened when I press this button.
(4) I copied the release files + MFC80 release redistributables + CRT80 release redistributables to another machine and guess what happened? As soon as I pressed the button I received a .NET dialog that said "The type initializer for <MODULE> threw an exception". This message is a bug in itself as we cannot find out what's wrong at this point.
However this problem only occurred when I used the user control created with C++/ CLI. If I used the C# user control it worked fine.
It is obvious that the problem is caused by the way C++/ CLI is creating the user control. I inserted the following code into my MFC application to find out the root cause of the problem:
//here we go!
AfxMessageBox(".NET exception: "+(CString)e->Message+"\nSource: "+(CString)e->Source);
AfxMessageBox("Inner exception: "+(CString)e->InnerException->Message);
After executing the application on the other PC the inner exception reported that msvcm80d.dll could not be found!!! Wow, what a confusing way to just find out that a library is missing? I started the release application on my development machine and looked carefully into the output window and I also saw my application loading the CRT80 debug libraries.
This problem must be caused by some project settings for my C++/CLI based user control. I found out, that by turning off the the problem is gone!
My Message to Microsoft is the following:
(1) The should be a clear error message if a library is missing. That even was the case with plain old DLLs. The message given in .NET 2.0 is useless.
(2) Default settings when creating a .NET user control in C++/CLI should be changed so that the release version doesn't cause debug libraries to be called by the hosting application!#4; Tue, 02 Oct 2007 17:57:00 GMT
- Hi - I've been having this problem as well. I've been using C# for ages without a problem but recently I've been forced to move over to C++ and can't get anything to run because of this (I've had to use Borland BuilderX - not my favourite).
I tried the solution you suggested but all that happened was a box popped up telling me I had debug info turned off (!)
I am completely at a loss - can you think of any other solutions to this or should I put it down as yet another of Visual C++s charming eccentricities and stick with Borland?#5; Tue, 02 Oct 2007 17:58:00 GMT