[英]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.