Visual Studio中另一个令人烦恼的随机错误。一切正常,现在当我尝试通过常规手段(F5)启动调试时,我收到此错误:
System.InvalidOperationException: 'An error occurred creating the form. See Exception.InnerException for details. The error is: No process is associated with this object.'
堆栈追踪:
at C64DebuggerGUI.My.MyProject.MyForms.Create__Instance__[T](T Instance)
at C64DebuggerGUI.My.MyProject.MyForms.get_cdbf()
at C64DebuggerGUI.My.MyApplication.OnCreateMainForm()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
at C64DebuggerGUI.My.MyApplication.Main(String[] Args)
代码中抓住异常的点:
Application.Designer.vb
Option Strict On
Option Explicit On
Namespace My
Partial Friend Class MyApplication
<Global.System.Diagnostics.DebuggerStepThroughAttribute()> _
Public Sub New()
MyBase.New(Global.Microsoft.VisualBasic.ApplicationServices.AuthenticationMode.Windows)
Me.IsSingleInstance = false
Me.EnableVisualStyles = true
Me.SaveMySettingsOnExit = true
Me.ShutDownStyle = Global.Microsoft.VisualBasic.ApplicationServices.ShutdownMode.AfterMainFormCloses
End Sub
<Global.System.Diagnostics.DebuggerStepThroughAttribute()> _
Protected Overrides Sub OnCreateMainForm()
Me.MainForm = Global.C64DebuggerGUI.cdbf ' < !!!!!!EXCEPTION HERE!!!!!!
End Sub
End Class
End Namespace
谷歌此时并不是我的朋友。类/形式C64DebuggerGUI.cdbf肯定存在。
我确实更改了一次owrked的启动表单,即它在调试器中启动到此子表单。但是,将其更改回cdbf.vb然后再次尝试子表单,在我的代码中的其他地方获得相同的错误。即:
System.InvalidOperationException: 'An error occurred creating the form. See Exception.InnerException for details. The error is: No process is associated with this object.'
在:
Private Sub Initialise()
Db = cdbf.MainDb
ToolsBindingSource.DataSource = Db.Tables("Tools") ' <-- !!! EXCEPTION HERE !!!
' truncated as code above just illustrative
我不确定这是我的代码还是VS的怪癖,但这是令人沮丧的地狱。这让我完全无法解决问题:(
如何解决此异常?
答案 0 :(得分:0)
哎哟。解决了它。罪魁祸首是cdbf.vb中的这段代码:
Private Sub RefreshC64DebugWnd()
If My.Settings.SuppressC64dAtStartup Then Return
ShowWindow(C64Dproc.MainWindowHandle, SW_HIDE)
wait(100)
ShowWindow(C64Dproc.MainWindowHandle, SW_MAXIMIZE)
End Sub
Private Sub MainSplitContainer_SplitterMoved(sender As Object, e As SplitterEventArgs) Handles MainSplitContainer.SplitterMoved
RefreshC64DebugWnd()
End Sub
我猜在实例化C64Dproc(进程)之前,splitter.moved事件被触发了。因此'未找到过程'错误。我猜是因为这是通过'非托管'(?)代码操纵的,VS无法指出我的罪魁祸首?
当然,真正具有讽刺意味的是,这是我班上的最后3行!