TypeInitializationException thrown for Program class

后端 未结 13 811
醉梦人生
醉梦人生 2020-12-10 23:30

My Windows Forms application was working earlier, however suddenly it stopped working. I am getting following exception:

相关标签:
13条回答
  • 2020-12-11 00:11

    I got the same error message and for my case the reason is my main program is set to build as 32 bit console app and I added a private variable logger which access a 64bit dll.

    public class Program
    {
        public static readonly Logger logger = new Logger(typeof(Program));
    

    After I changed the main program to be build as 64bit, the issue is fixed.

    0 讨论(0)
  • 2020-12-11 00:12

    I've the same problem: runs program in MS VS 2015 and triggers an exception message:

    System.TypeInitializationException was unhandled
    Message: An unhandled exception of type 'System.TypeInitializationException' occurred in mscorlib.dll
    Additional information: Der Typeninitialisierer für "<Module>" hat eine Ausnahme verursacht.
    

    The question where source this exception? So, I started the EXE file and displayed the exception message dialog. Answer on "debug mode" with MS VS so become more information displayed about exception.

    System.IO.FileNotFoundException was unhandled
        Message: An unhandled exception of type 'System.IO.FileNotFoundException' occurred in mscorlib.dll
        Additional information: Die Datei oder Assembly "SIC, Version=19.2.6.3, Culture=neutral, PublicKeyToken=**************" oder eine Abhängigkeit davon wurde nicht gefunden. Das System kann die angegebene Datei nicht finden.
    

    I go to this reference and analyse properties Property: "Copy Local" is on false - because before was a installed into GAC Solution: property "Copy Local" set on true and builds new assembly and works :-)

    Maybe this information helpful! So have a good day.

    0 讨论(0)
  • 2020-12-11 00:14

    I've got the same error with platform target set as any CPU and prefer 32-bit checked, unchecking that last one solved my problem.

    0 讨论(0)
  • 2020-12-11 00:14

    In my case it was a very silly thing. I had accidentally typed something like this

    <configuration>
        <appSettings>
             <add key="someKey" value="SomeValue" />sss
             <add key="someKey1" value="SomeValue1" />
        </appSettings>
    </configuration> 
    

    sss - Caused the error for me. Any random character entry.

    0 讨论(0)
  • 2020-12-11 00:16

    This issue for me was caused by a rogue user.config file that was created in the AppData\Local[Manufacturer][Product Name] directory. I'm not sure how it got there, but seems to be created every now and then.

    0 讨论(0)
  • 2020-12-11 00:18

    A possible reason: init a static dictionary with duplicated keys.

    0 讨论(0)
提交回复
热议问题