Jump to content

Exception has been thrown by the target of an invocation

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
1 reply to this topic

#1
tgp1994

tgp1994

    Newbie

  • Members
  • Pip
  • 2 posts
Hi everyone. I'm making a multiform program here, and one problem I've discovered is, Visual Studio seems to not want to go to the heart of my problem here, instead it seems to stop right where my main form opens a different one.

The thing here is, I want to pass all focus onto that new form. I want it to be the main form, and I want the previous one to be forgotten about. I would also like the debugger to get comfortable with this form. Here's the code that opens up the second form:


Try

            SetupGuide.Show()

        Catch ex As Exception

            MsgBox("Caught error: " + vbNewLine + vbNewLine + ex.ToString)

        End Try

        Me.Close()


The problem is, it never catches the exception there, but the built in VS debugger somehow does, halting my program with all of the details on why this invocation failed.

So really, my main issue now is how I change this from being an invocation, to more being a passing of control. Also, here is the entire exception:


System.Reflection.TargetInvocationException was unhandled

  Message="Exception has been thrown by the target of an invocation."

  Source="mscorlib"

  StackTrace:

       at System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)

       at System.RuntimeMethodHandle.InvokeMethodFast(Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)

       at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)

       at System.Delegate.DynamicInvokeImpl(Object[] args)

       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.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 Server1Up.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()

  InnerException: System.NullReferenceException

       Message="Object reference not set to an instance of an object."

       Source="Server1Up"

       StackTrace:

            at Server1Up.SetupGuide.filedl_DownloadFileCompleted(Object sender, AsyncCompletedEventArgs e) in C:\Documents and Settings\*******\My Documents\Visual Studio 2008\Projects\Server1Up\SetupGuide.vb:line 96

            at System.Net.WebClient.OnDownloadFileCompleted(AsyncCompletedEventArgs e)

            at System.Net.WebClient.DownloadFileOperationCompleted(Object arg)

       InnerException: 


Also, here is the code where it says it is tripping up:


Private Sub filedl_DownloadFileCompleted(ByVal sender As Object, ByVal e As System.ComponentModel.AsyncCompletedEventArgs) Handles filedl.DownloadFileCompleted

        MsgBox("Done.")

        MsgBox(e.Error.GetType) 'Program halts right here.

        If e.Error Is Nothing Then

            statusprogressbar.Value = 0

            Label_StatusIndicator.Text = "Launching installer..."

            installerprocess.StartInfo.FileName = (My.Settings.serverPath + "\installer.exe")

            installerprocess.Start()

            installerprocess.EnableRaisingEvents = True

        Else

            MsgBox("There was an error while downloading the file:" + vbNewLine + vbNewLine + e.Error.ToString)

        End If

    End Sub



#2
tgp1994

tgp1994

    Newbie

  • Members
  • Pip
  • 2 posts
Ah, it turns out that I was attempting to access e.Error.Tostring when in reality it was non-existant. (Wouldn't tostring return Nothing?) Anyhow, I still don't understand why VS's debugger didn't go to the root of problem there. Anyone know why?