how to solve System.TypeInitializationException was unhandled exception in vb.net?

后端 未结 4 783
傲寒
傲寒 2020-12-19 16:44

I have created a vb.net console application when i am running the source code it will work fine.But when i am running the Executable file it is throwing an exeption like \

相关标签:
4条回答
  • 2020-12-19 17:19

    When I encountered this issue, the exception pointed to a line of code that was actually not related to the configuration item that was missing from the Web.Config file. Basically I was using a Constants.cs file to initialise settings from the Web.config file that were then used in the code. One of these constants was missing from the Web.config file and simply adding this setting to the Web.config file resolved the issue.

    0 讨论(0)
  • 2020-12-19 17:21

    In my case, it was a console app that was instantiating some static variables from config and the config entries were missing:

    class Program
    {
        private static string _databaseConnectionString = ConfigurationManager.ConnectionStrings["database"].ConnectionString;
    
        public static int Main(string[] args)
        {
            ...
        }
    }
    

    It never hit the breakpoint inside main because it happened as the class was being instantiated, before it hit the main method.

    0 讨论(0)
  • 2020-12-19 17:28

    In my case, this error turned out to be a typo in a read-only local variable. "20017" is not a valid year. Unfortunately, I wasted a lot of time diagnosing. The error message was not helpful.

    private static readonly DateTime end_date = Convert.ToDateTime("7/7/20017");
    
    0 讨论(0)
  • 2020-12-19 17:29

    Generally, a TypeInitializionException is thrown when another exception happens inside a static constructor.

    Check for the InnerException property of the former, and you will get more information about the actual error.

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