当我执行“DEBUG -> Start Debugging”和“DEBUG -> Start Without Debugging”时,我在 VS2013 中得到了不同的堆栈跟踪。似乎外部异常正在被丢弃。
这是我执行“DEBUG -> Start Debugging”时得到的结果(注意外部异常):
EmgNet.Exceptions.SQLExecutionException: Incorrect syntax near 'Heights_xlsx'.
Failed while executing: 'IF OBJECT_ID('tempdb..#mapping_Heights_xlsx') IS NOT NULL DROP TABLE #mapping_Heights_xlsx' ---> System.Data.SqlClient.SqlException: Incorrect syntax near 'Heights_xlsx'.
at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection)
at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj)
at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
at System.Data.SqlClient.SqlCommand.EndExecuteNonQuery(IAsyncResult asyncResult)
at EmgNet.DataLib.ExecSql(String SqlText, IDbConnection& Connection, Int32 CommandTimeout, IDbTransaction& Transaction, String MultipleRowSeparator, Object FieldNames, SqlExecType ExecType) in C:\DevHome\TFS\Projects\DataLib.vb:line 4181
--- End of inner exception stack trace ---
at EmgNet.DataLib.ExecSql(String SqlText, IDbConnection& Connection, Int32 CommandTimeout, IDbTransaction& Transaction, String MultipleRowSeparator, Object FieldNames, SqlExecType ExecType) in C:\DevHome\TFS\Projects\DataLib.vb:line 4207
at EmgNet.DataHandler.ExecSql(String SqlText, IDbConnection& Connection, Int32 CommandTimeout, IDbTransaction& Transaction, String MultipleRowSeparator, Object FieldNames, SqlExecType ExecType) in C:\DevHome\TFS\Projects\DataHandler.vb:line 1248
at EmgNetExt.SimpleFileImporterMapper.LoadFileInternal(String file) in C:\DevHome\TFS\Projects\DataLoaderWithMapper\SimpleFileImporterMapper.vb:line 36
at EmgNetExt.AFileImporterMapper.LoadFile(String file) in C:\DevHome\TFS\Projects\DataLoaderWithMapper\AFileImporterMapper.vb:line 19
at EmgNetExt.frmDataLoaderWithMapper.LoadFile() in C:\DevHome\TFS\Projects\DataLoaderWithMapper\frmDataLoaderWithMapper.vb:line 130
at EmgNetExt.frmDataLoaderWithMapper.frmDynamicDataLoader_Shown(Object sender, EventArgs e) in C:\DevHome\TFS\Projects\DataLoaderWithMapper\frmDataLoaderWithMapper.vb:line 55
at System.Windows.Forms.Form.OnShown(EventArgs e)
at System.Windows.Forms.Form.CallShownEvent()
at System.Windows.Forms.Control.InvokeMarshaledCallbackDo(ThreadMethodEntry tme)
at System.Windows.Forms.Control.InvokeMarshaledCallbackHelper(Object obj)
at System.Threading.ExecutionContext.runTryCode(Object userData)
at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Windows.Forms.Control.InvokeMarshaledCallback(ThreadMethodEntry tme)
at System.Windows.Forms.Control.InvokeMarshaledCallbacks()
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
at System.Windows.Forms.ContainerControl.WndProc(Message& m)
at System.Windows.Forms.Form.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(Int32 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.RunDialog(Form form)
at System.Windows.Forms.Form.ShowDialog(IWin32Window owner)
at System.Windows.Forms.Form.ShowDialog()
at frmStart.NewImportToolStripMenuItem_Click(Object sender, EventArgs e) in C:\DevHome\TFS\Projects\frmStart.vb:line 3358
at System.Windows.Forms.ToolStripItem.RaiseEvent(Object key, EventArgs e)
at System.Windows.Forms.ToolStripMenuItem.OnClick(EventArgs e)
at System.Windows.Forms.ToolStripItem.HandleClick(EventArgs e)
at System.Windows.Forms.ToolStripItem.HandleMouseUp(MouseEventArgs e)
at System.Windows.Forms.ToolStripItem.FireEventInteractive(EventArgs e, ToolStripItemEventType met)
at System.Windows.Forms.ToolStripItem.FireEvent(EventArgs e, ToolStripItemEventType met)
at System.Windows.Forms.ToolStrip.OnMouseUp(MouseEventArgs mea)
at System.Windows.Forms.ToolStripDropDown.OnMouseUp(MouseEventArgs mea)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
at System.Windows.Forms.ToolStrip.WndProc(Message& m)
at System.Windows.Forms.ToolStripDropDown.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(Int32 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(ApplicationContext context)
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
at My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 81
at System.AppDomain._nExecuteAssembly(Assembly 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)
at System.Threading.ThreadHelper.ThreadStart()
这是我执行“DEBUG -> Start Without Debugging”时得到的结果(注意没有外部异常):
System.Data.SqlClient.SqlException: Incorrect syntax near 'Heights_xlsx'.
at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection)
at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj)
at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
at System.Data.SqlClient.SqlCommand.EndExecuteNonQuery(IAsyncResult asyncResult)
at DataLib.ExecSql(String SqlText, IDbConnection& Connection, Int32 CommandTimeout, IDbTransaction& Transaction, String MultipleRowSeparator, Object FieldNames, SqlExecType ExecType) in C:\DevHome\TFS\Projects\DataLib.vb:line 4181
我对为什么会发生这种情况感到困惑。为什么在使用调试器运行或不使用调试器运行时堆栈跟踪会发生变化?
最佳答案
在 visual studio 中,如果转到菜单调试 -> 异常,您将看到一个包含公共(public)语言运行时异常、托管调试助手等异常的表单。根据此设置,堆栈跟踪之间的差异通常与 Visual Studio 不同,它可能会更早中断,也可能根本不会中断,只会继续尝试运行。如果您想要比这更详细的信息,那么希望其他人可以回答。我只知道这通常是堆栈跟踪不同的原因。
关于c# - 使用 "Start Debugging"和 "Start Without Debugging"启动应用程序时的不同堆栈跟踪,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26126011/