Invocation Error.

Ive written a little app in vb.net when i run the app i some times get a invocation error. the error saysTargetInvocationException was unhandled. After this has happened i cant debug my code beacuse my breakpoints dont work.

If i tick the "Allow source code to be different from original version" box under the "location" option in the breakpoint menu i get another error saying that the source code cant be found. Last time this happened i published the project and it sorted the problem out.

But i since got the Invocation error back and now the project wont publish because it says that the "certificate cant be signed".

How do i handle this exception and what casuses this error.

My code is a bit messy im using a second thread and its the first time ive used multithreading so im still learning.

Im reletivly new to vb.net and im pulling my hair out with this problem because i cant even debug my app now.

Oh yeah ive to build it and rebuild it and clean it, it all works or at least the complier says that it worked but the breakpoint error still happens.

im using visual studio 2005 Pro

Thanks.



Answer this question

Invocation Error.

  • Luxsy

    This is whats causing the error,

    Private Sub ThreadCopy_DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles ThreadCopy.DoWork

    Dim objLock As Object = New Object

    ThreadCopy.WorkerReportsProgress = True

    SyncLock objLock

    Copy(strGlobalSource, strGlobalDest)

    End SyncLock

    End Sub

    Copy is a procedure that copies a file from one destination to another. Its only called from this event and the variables strGlobalSource and StrGlobalDest are only used by this event. They are given values when the program loads up.

    Thanks


  • Viniciusgf

    Im really confused now. Its not the code i posted before thats starts the error. When the error happens the debugger doesnt highlight any code it just shows me the error so i dont know whats causing the problem.

    Ive looked into what it all means but its just says somthing about reflection i dont even know what reflection is. Can someone please let me know how to handle the error. Its really bugging me now.

    The strange thing is it didnt use to happen but now it happens all the time and i havent even changed my code.


  • soung

    The above details mention line 81 this is whats on that line

    Public Sub ShowFrmMain(ByVal bolStealthArg As Boolean) '//LINE 81

    If bolStealthArg = True Then

    sysTray.Visible = True

    Me.Visible = False

    Else

    sysTray.Visible = False

    Me.Visible = True

    Me.WindowState = FormWindowState.Normal

    Me.StartPosition = FormStartPosition.CenterScreen

    Me.Show()

    End If

    End Sub


  • wanwiz

    Hi,

    After you click on the blue STOP square in Visual Studio can you post your code here please or the SUB or FUNCTION or the MODULE or the CLASS the error occurs in at least

     It should stop with the exception by highlighting the problem line.

     

    Regards,

    S_DS

     



  • SHRESHTH

    I copied the details of the exception and here they are.

    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 BMS.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 81
    at System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)
    at System.Runtime.Hosting.ManifestRunner.Run(Boolean checkAptModel)
    at System.Runtime.Hosting.ManifestRunner.ExecuteAsAssembly()
    at System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext activationContext, String[] activationCustomData)
    at System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext activationContext)
    at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssemblyDebugInZone()
    at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
    at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
    at System.Threading.ThreadHelper.ThreadStart()


  • Invocation Error.