2

私は途方に暮れています。NullReferenceException(オブジェクトのインスタンスに設定されていないオブジェクト参照)を使用して実行してから数分後にクラッシュするアプリケーションがあります。通常は問題なく対処できますが、Visual Studio が壊れると、問題が で発生していることがわかりApplication.Run(new Main());ます。これのトラブルシューティングを開始するために何をすべきかわかりません。コール スタックはその行を指しているだけなので、何の役にも立ちませんApplication.Run(new Main());

Visual Studio の例外ウィンドウ ( CTRL + ALT + E) に入り、すべての例外を報告するように指示しました。これを取得する前に問題が見つかることを望んでいましたNullReferenceException。しかし、運がありません。

この問題を見つけるのに役立つツールは何ですか?

編集:

Visual Studio によって報告されたコール スタックは次のとおりです。

StackTrace:
       at GMap.NET.WindowsForms.GMapOverlay.DrawRoutes(Graphics g)
       at GMap.NET.WindowsForms.GMapOverlay.Render(Graphics g)
       at GMap.NET.WindowsForms.GMapControl.OnPaintOverlays(Graphics g)
       at GMap.NET.WindowsForms.GMapControl.OnPaint(PaintEventArgs e)
       at System.Windows.Forms.Control.PaintWithErrorHandling(PaintEventArgs e, Int16 layer)
       at System.Windows.Forms.Control.WmPaint(Message& m)
       at System.Windows.Forms.Control.WndProc(Message& m)
       at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
       at System.Windows.Forms.UserControl.WndProc(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
       at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
       at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
       at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.Run(Form mainForm)
       at Foxhunt.Client.Program.Main() in C:\Users\Michael\Documents\Visual Studio 2010\Projects\Foxhunt.Client\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()
4

3 に答える 3

4

この例外は実際にはサードパーティのコードでスローされていますが、Visual Studio ではそれが表示されません。

例外のスタック トレースを見て、完全なスタックを確認します。

于 2012-12-19T19:56:12.750 に答える
3

コードのどこかに未処理の例外がある可能性があります。以下を追加して、詳細情報が得られるかどうかを確認してください。

static void Main()
{
  Application.ThreadException += ThreadException;
  AppDomain.CurrentDomain.UnhandledException += UnhandledException;

  Application.EnableVisualStyles();
  Application.SetCompatibleTextRenderingDefault(false);
  Application.Run(new Main());
}

private static void ThreadException(object sender, ThreadExceptionEventArgs e)
{
  MessageBox.Show(e.Exception.ToString());
}

private static void UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
  MessageBox.Show(e.ExceptionObject.ToString());
}
于 2012-12-19T18:21:02.983 に答える
1

これはいくつかの場所にある可能性があります。コードを次のように変更します

var mf = new Main();
Application.Run(mf);

最初の行が倒れた場合、問題はコンストラクタチェーンのどこかにあります

2番目の場合は、初期化チェーンのどこかにあります

Main()クラスの関連するすべてのメソッドで赤い斑点を打ち始め、追跡するまでステップします。

于 2012-12-19T18:09:05.483 に答える