简体   繁体   English

我遇到了异常:'mws.Options_DB'的类型初始化器引发了异常。 这是什么意思?

[英]I got exception: The type initializer for 'mws.Options_DB' threw an exception. what does it mean?

What could be the problem ? 可能是什么问题呢 ? The exception happen each time the same exception. 每次相同的异常都会发生该异常。 This is the line that throw the exception when i click a button and call it: 这是在我单击按钮并将其调用时引发异常的行:

public void Save()
        {
            Options_DB.Set_Points_Coordinates_List(Point_X);
        }

The Point_X is a List of type Float Point_X是Float类型的列表

Cant figure out how ot fix the problem. 无法找出解决问题的方法。

I have in Form1 a button click event where i call there the function above in another class: Save() 我在Form1中有一个按钮单击事件,在这里我在另一个类中调用上面的函数:Save()

I used a breakpoint on it when its doing the line in the Save() function its going ot the Options_DB class and doing in the top of it: 当它在Save()函数中执行以下代码时(在Options_DB类中进行操作并在其顶部执行操作),我在其中使用了断点:

static List<float> Points_Coordinates;
        static string settings_dir;
        static string settings_file;
        static OptionsFile setting_file;
        static string path_settings;
        static string path_exe;

        static Options_DB()
        {
            // ---  O P E N N I N G   S E T T I N G   F I L E   
            //t = voices_volume_trackbar.ToString();
            path_exe = Path.GetDirectoryName(Application.LocalUserAppDataPath);
            path_settings = Path.GetDirectoryName(Application.LocalUserAppDataPath);
            settings_file = "\\settings.txt";
            settings_dir = path_settings + @"\settings";
            setting_file = new OptionsFile(settings_dir + settings_file);

When its getting to the line: setting_file = new OptionsFile(settings_dir + settings_file); 当它到达该行时: setting_file = new OptionsFile(settings_dir + settings_file); its getting to the OptionsFile class and there its trying to create the directory and file in the exception: 它进入OptionsFile类,并尝试在异常中创建目录和文件:

string path_exe;
        string temp_settings_file;
        string temp_settings_dir;
        string Options_File;
        StreamWriter sw;
        StreamReader sr;

/*----------------------------------------------------------
 * Function     : OptionsFile
 * Description  : Constructor
 * Parameters   : file_name is the name of the file to use
 * Return       : none
 * --------------------------------------------------------*/
    public OptionsFile(string settings)
    {

        if (File.Exists(settings))
        {

        }
        else
        {
        FileStream fs=File.Create(settings);

But once the breakpoint is on the line File.Create(settings); 但是一旦断点在行File.Create(settings); and i see that settings containing the path and file name instead of creating them its jumping back to the Save() function to the line inside there and then throw the exception. 而且我看到包含路径和文件名的设置,而不是创建它们,然后跳回Save()函数到那里的行,然后引发异常。

Why its jumping to the Save() and not creating the path and file ? 为什么跳转到Save()而不创建路径和文件?

That exception means that some static member of that type could not be initialized or the static constructor for that type failed. 该异常意味着无法初始化该类型的某些静态成员,或者该类型的静态构造函数失败。 Check those. 检查那些。

Your stacktrace clearly indicates that the problem is 您的堆栈跟踪明确表明问题是

at mws.Options_DB..cctor() in D:\\C-Sharp\\AnimationEditor\\AnimationEditor\\Options_DB.cs:line 30 在D:\\ C-Sharp \\ AnimationEditor \\ AnimationEditor \\ Options_DB.cs:行30中的mws.Options_DB..cctor()

.cctor() is the static constructor. .cctor()是静态构造函数。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 System.TypeInitializationException: &#39;Bid&#39; 的类型初始值设定项引发异常。 - System.TypeInitializationException: 'The type initializer for 'Bid' threw an exception.' System.TypeInitializationException:&#39;类型初始值设定项引发了异常。 - System.TypeInitializationException: 'The type initializer threw an exception.' “Microsoft.AspNetCore.Mvc.MvcCoreLoggerExtensions”的类型初始值设定项引发异常。 - The type initializer for 'Microsoft.AspNetCore.Mvc.MvcCoreLoggerExtensions' threw an exception.' 如何调试“WindowsFormsAutoClick.Form1的类型初始化程序”引发异常。“? - How to debug “Type initializer for 'WindowsFormsAutoClick.Form1' threw an exception.”? 为什么Class不断抛出“ MyClass的类型初始值设定项引发异常”。 - Why Class keeps throwing 'The type initializer for 'MyClass' threw an exception.' “Azure.Core.Pipeline.HttpClientTransport”的类型初始化程序引发了异常。 - The type initializer for “Azure.Core.Pipeline.HttpClientTransport” threw an exception.' &#39;&#39;的类型初始值设定项引发了异常 - The type initializer for '' threw an exception 类型初始值设定项引发了异常 - The type initializer threw an exception 类型初始值设定项引发异常 - Type initializer threw an exception 我得到“'Microsoft.Cct.CctProjectNode'的类型初始化程序引发异常。”在安装Azure SDK 2.9后打开ccproj文件时 - I get “The type initializer for 'Microsoft.Cct.CctProjectNode' threw an exception.” when opening ccproj files after installing Azure SDK 2.9
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM