开发者

System.TypeInitializationException was unhandled

What does it mean when MS Visual Studio 2005 throws this message?

"The type initializer for 'RMDC.clsVariables' threw an exception."

Error log is as follows

System.TypeInitializationException was unhandled
  Message="The type initializer for 'RMDC.clsVariables' threw an exception."
  Source="RMDC"
  TypeName="RMDC.clsVariables"
  StackTrace:
       at RMDC.clsFunctions.getRegistryValue() in D:\Magnus Project\Project Backup\RMDC\RMDC\Class\clsFunctions.cs:line 704
       at RMDC.Program.Main() in ..\RMDC\RMDC\Program.cs:line 39
       at System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()

The class with error in question

using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;
using System.Data;
using System.Windows.Forms;
using System.Collections;


namespace RMDC
{
    class clsVariables
    {
        public SqlConnection conn = new SqlConnection();

        public SqlDataAdapter sAdapter = new SqlDataAdapter();
        public DataSet sDataSet = new DataSet();

        public static string sMessageBox = "开发者_开发百科";
        public static string sUsername;
        public static string sUserFullname;
        public static string sUserLogin;
        public static string sUserType;
        public static int sUserID;
        public static string sServer = "system-10";
        public static string sDatabase = "";
        public static string sDBUserID = "";
        public static string sDBPassword = "";
        public static bool sDontShow = false;
        public static string sCompanyName;
        public static string sContactName;
        public static string sCompanyAddress;
        public static string sPhoneNumber;
        public static string sFaxNumber;
        public static string sEmailAddress;
        public static string sWebAddress;
        public static string sOfficeCd = "01";
        public static int sfiscalYrId = 1;
        public static string sfiscalYr;
        public static DateTime sFiscalStart = DateTime.Today;
        public static DateTime sFiscalEnd = DateTime.Today;
        public static int sRoleId;

        public static byte[] m_barrImg;

        public static SqlConnection cnn = new SqlConnection();

        public OpenFileDialog openIMG = new OpenFileDialog();

        public static NepEngCalanderProvider.NepEngDateClass nepDate = new NepEngCalanderProvider.NepEngDateClass();
        public static NumberToWord.InWordsClass NumericWords = new NumberToWord.InWordsClass();


        public enum QueryType
        {
            Insert,
            Update,
            Delete
        }
    }
}


Well, it means what it said - something in the type initializer for RMDC.clsVariables (which is an unconventional name, btw) went bang.

This could be a static variable initializer:

static int foo = GetInitialValueForFoo();

or a static constructor:

static clsVariables
{
    DoSomething();
}

Whatever it was, it failed, leaving your type unusable.

If you run the code in the debugger, it should break in as soon as the exception is thrown, making it easier to work out what's going on.


You have to look at the exception's InnerException to find the reason that the TypeInitializationException got raised. It's impossible to guess what's wrong without that information.

What ever code generated the error log needs a bit of work so that it doesn't forget to display the inner exception as well. That's automatic if you use the Exception.ToString() method. Implement an event handler for AppDomain.CurrentDomain.UnhandledException if necessary, log the value of e.ExceptionObject.ToString().

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜