![](/img/trans.png)
[英]System.TypeInitializationException: 'The type initializer for 'Bid' threw an exception.'
[英]I got exception: The type initializer for 'mws.Options_DB' threw an exception. what does it mean?
可能是什么問題呢 ? 每次相同的異常都會發生該異常。 這是在我單擊按鈕並將其調用時引發異常的行:
public void Save()
{
Options_DB.Set_Points_Coordinates_List(Point_X);
}
Point_X是Float類型的列表
無法找出解決問題的方法。
我在Form1中有一個按鈕單擊事件,在這里我在另一個類中調用上面的函數:Save()
當它在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);
當它到達該行時: setting_file = new OptionsFile(settings_dir + settings_file);
它進入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);
但是一旦斷點在行File.Create(settings); 而且我看到包含路徑和文件名的設置,而不是創建它們,然后跳回Save()函數到那里的行,然后引發異常。
為什么跳轉到Save()而不創建路徑和文件?
該異常意味着無法初始化該類型的某些靜態成員,或者該類型的靜態構造函數失敗。 檢查那些。
您的堆棧跟蹤明確表明問題是
在D:\\ C-Sharp \\ AnimationEditor \\ AnimationEditor \\ Options_DB.cs:行30中的mws.Options_DB..cctor()
.cctor()是靜態構造函數。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.