Click here to Skip to main content
11,638,881 members (70,062 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++ C++/CLI
I have a c++/cli project and it's a windows application. In debug mode we didn't have any problems but after taking it to release mode this error start up. I searched and found some forum-answers but couldn't help me solve this problem.
Please help me ....

Error :

An unhandled exception of type 'System.TypeInitializationException' occurred in Unknown Module.

Additional information: The type initializer for 'Module' threw an exception.
Posted 22-Mar-10 3:06am
Edited 5-May-11 8:22am
v2
Comments
sharifani at 1-Nov-12 11:40am
   
who can i resolve error " the type initializer 'MODUl' threw an exception.i can install microsoft visual studio 2010 ultimate,but that error ocured and vs not running.please help me.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Does the machine where the application is running has all the required dlls??

Maybe you are missing some interops in the local directory
  Permalink  
Comments
Prasad_Kulkarni at 5-Jun-12 1:24am
   
Good one +5
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 5

I had the same error and found that the class I was referencing was not the problem, but it had a static variable of another type declared that required another assembly to load. That assembly was built for a target platform of x86 (see Properties-->Build tab) however the main project was compiled for Any CPU. I rebuilt the older assembly for Any CPU... problem solved.

Here are some helpful steps for finding the root cause of this problem...

Click Debug--> Exceptions and check ON all the Thrown checkboxes. This will cause the debugger to stop on all first chance exceptions and will help you find the error under the Type Initializer error that you're seeing. If it is related to another assembly, as mine was, you can use Microsoft's Assembly Binding Log Viewer tool to help determine the problem.
  Permalink  
Comments
benben88 at 20-Jun-14 12:12pm
   
This helped me! Initializing all of the "thrown" actually gives you a better insight as to what is happening to get this bigger error. Many thanks!
bnem at 12-Aug-14 13:34pm
   
Thanks! Ticking all of the "thrown" checkboxes under Debug --> Exceptions was a great help!
Member 10273358 at 8-Dec-14 20:49pm
   
Very good solution. It fast helped me find the error that I declared a const std::set with incorrect initialization arguments. It occurs before main() entry, so without this, it's really hard to find it out!
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

I recently had the same problem, and it was because I was using Date.Parse on a missing element in the config file:

Date.Parse(System.Configuration.ConfigurationManager.AppSettings.Get("frex"))
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

change your .net framework to lower Wink | ;)
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 11

In my case (so many different cases where this shows up) I was initializing some static fields in their declaration, like this:

public class MyHelperClass
{
    readonly static SolidColorBrush BlueBrush = new SolidColorBrush(Colors.Blue);
    
    public static void ApplyBrush()
    { 
      // do something with brush 
    }
}

When I moved the initialization into a static constructor, the exception was no longer thrown:

public class MyHelperClass
{
  readonly static SolidColorBrush BlueBrush;
  
  static MyHelperClass
  {
    BlueBrush = new SolidColorBrush(Colors.Blue);
  }
}
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 7

look the repository container in unity.config
<pre><pre lang="xml">
<unity xmlns="http://schemas.microsoft.com/practices/2010/unity">
  <alias type="App.Core.Interfaces.IRepositoryConfiguration, App.Core" alias="IRepositoryConfiguration" />
  <alias type="App.Repository.Mappings.SqlServer.SqlRepositoryConfigurer, App.Repository.Mappings.SqlServer" alias="SqlRepositoryConfigurer" />
 
  <container name="RepositoryContainer">
    <register type="IRepositoryConfiguration" mapTo="SqlRepositoryConfigurer" >
      <lifetime type="singleton"/>
    </register>
  </container>
</unity>
</pre></pre>
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 9

I was making an assignment in a constructor that didn't have an error handling.

fileInfo = My.Computer.FileSystem.GetFileInfo(logDirLoc & logFileName)
writer = fileInfo.AppendText()

When I removed it the issue was solved.

tip: I looked through the error details and saw that a file couldn't be found. That was it.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 10

I faced the Same error that is "System.TypeInitializationException". This error is raised due to Static constructor .

Actually in my case i am accessing some value from the App.config and assigning that value in a static variable . The error is because of the App.config file . That means the app.config file is not well formed (I just missed some tag on app.config ). After putting the missing tag it works fine.
  Permalink  
Comments
SolvingAll at 24-Sep-14 9:53am
   
Actually it was fixed my error.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 12

May be you have encrypted your solution's Web.config's AppSetting section or any section at a machine
and now you want to compile your solution at different machine or want to use that web.config file at different machine

Solution: You need to decrypt that web.config file on the same machine to use AppSettings section or any section in web.config file

This worked for me.
  Permalink  
Comments
Deepu S Nair at 18-Feb-15 1:49am
   
not an answer
jeron1 at 18-Feb-15 10:40am
   
I sure hope the dates on these posts are wrong, otherwise this might the longest active thread I've seen here.
Stefan_Lang at 19-Feb-15 4:55am
   
downvoted for thread-necromancy
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 13

The type initializer for 'Module' threw an exception.
Just Run IISRESET
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 9,061
1 Sergey Alexandrovich Kryukov 8,773
2 Mika Wendelius 7,027
3 Suvendu Shekhar Giri 2,494
4 F-ES Sitecore 2,438


Advertise | Privacy | Mobile
Web03 | 2.8.150728.1 | Last Updated 22 Feb 2015
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100