[英]I'm getting type initializer exception and can't find out what's wrong
當我啟動應用程序時,我得到了異常信息,那是什么?
異常在構造函數中:
checkBox1.Checked = Options_DB.Get_Automatic_Start();
這是options_db
類,但我在那里使用了一個斷點,但它從未到達options_db
這是在form1中引發異常的構造函數:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using DannyGeneral;
using System.Drawing.Drawing2D;
namespace Batch_Images_Convertion
{
public partial class Form1 : Form
{
int i;
bool cancel_;
bool automatic_;
public Form1()
{
InitializeComponent();
i = 0;
automatic_ = false;
checkBox1.Checked = Options_DB.Get_Automatic_Start();
它永遠不會超出這一界限。
這是異常錯誤消息:
System.TypeInitializationException was unhandled
Message=The type initializer for 'Batch_Images_Convertion.Options_DB' threw an exception.
Source=Batch_Images_Convertion
TypeName=Batch_Images_Convertion.Options_DB
StackTrace:
at Batch_Images_Convertion.Options_DB.Get_Automatic_Start()
at Batch_Images_Convertion.Form1..ctor() in D:\C-Sharp\Batch_Images_Convertion\Batch_Images_Convertion\Batch_Images_Convertion\Form1.cs:line 26
at Batch_Images_Convertion.Program.Main() in D:\C-Sharp\Batch_Images_Convertion\Batch_Images_Convertion\Batch_Images_Convertion\Program.cs:line 18
at System.AppDomain._nExecuteAssembly(RuntimeAssembly 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, Boolean ignoreSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException: System.IO.DirectoryNotFoundException
Message=Could not find a part of the path 'C:\Users\Chocolade\AppData\Local\Microsoft\Batch_Images_Convertion\settings\settings_convertion.txt'.
Source=mscorlib
StackTrace:
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options)
at System.IO.File.Create(String path)
at DannyGeneral.OptionsFile..ctor(String settings) in D:\C-Sharp\Batch_Images_Convertion\Batch_Images_Convertion\Batch_Images_Convertion\OptionsFile.cs:line 72
at Batch_Images_Convertion.Options_DB..cctor() in D:\C-Sharp\Batch_Images_Convertion\Batch_Images_Convertion\Batch_Images_Convertion\Options_DB.cs:line 25
InnerException:
看起來它試圖加載文件'C:\\Users\\Chocolade\\AppData\\Local\\Microsoft\\Batch_Images_Convertion\\settings\\settings_convertion.txt'
但目錄settings
不存在。
在構造函數中,通過執行以下操作來檢查目錄是否存在:
Directory.Exists(@"path\to\your\folder")
嘗試訪問文件之前。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.