Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

Visual Studio Add-in crashes with an "TargetInvocationException" error message


View products that this article applies to.

Symptoms

When running an Add-in or Integration package, Microsoft Visual Studio 2013 may unexpectedly terminate with an unhandled exception of type System.Reflection.TargetInvocationException.

In the Application Event log, you will see an Application Error with text similar to:

Faulting application name: devenv.exe, version: 12.0.21005.1, time stamp: 0x524fcb34
Faulting module name: KERNELBASE.dll, version: 6.1.7601.18229, time stamp: 0x51fb10c6
Exception code: 0xe0434352
Fault offset: 0x0000812f
Faulting process id: 0xe3c
Faulting application start time: 0x01cf0b21c6346ea8
Faulting application path: C:\Program Files\Microsoft Visual Studio 12.0\Common7\IDE\devenv.exe
Faulting module path: C:\Windows\system32\KERNELBASE.dll

This is followed by an event with .NET Runtime as the source with text similar to:

Application: devenv.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.Reflection.TargetInvocationException
Stack:
at System.RuntimeMethodHandle.InvokeMethod(System.Object, System.Object[], System.Signature, Boolean)
at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(System.Object, System.Object[], System.Object[])
at System.Delegate.DynamicInvokeImpl(System.Object[])
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate, System.Object, Int32)
at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(System.Object, System.Delegate, System.Object, Int32, System.Delegate)
at System.Windows.Threading.DispatcherOperation.InvokeImpl()
at System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(System.Object)
at System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)
at System.Windows.Threading.DispatcherOperation.Invoke()
at System.Windows.Threading.Dispatcher.ProcessQueue()
at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr, Int32, IntPtr, IntPtr, Boolean ByRef)
at MS.Win32.HwndWrapper.WndProc(IntPtr, Int32, IntPtr, IntPtr, Boolean ByRef)
at MS.Win32.HwndSubclass.DispatcherCallbackOperation(System.Object)
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate, System.Object, Int32)
at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(System.Object, System.Delegate, System.Object, Int32, System.Delegate)
at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(System.Windows.Threading.DispatcherPriority, System.TimeSpan, System.Delegate, System.Object, Int32)
at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr, Int32, IntPtr, IntPtr)

↑ Back to the top


Cause

This issue occurs because a code change in the Visual Studio IDE in 2013 and affects documents that are not valid path names as parsed by the .NET System.IO.File class. Visual Studio may throw a System.ArgumentException when opening these documents which is bubbled up through the IDE as the TargetInvocationException.

↑ Back to the top


Resolution

You can avoid or work around the issue by making sure that your document names are valid Win32 file names.

This issue has been fixed in Visual Studio 2013 Update 2 and later versions of Visual Studio.

↑ Back to the top


More Information

An example call stack of the TargetInvocationException is shown below. This is from a process dump file captured on the unhandled exception and displayed in the WindDdbg debugger using the SOS extensions to display managed exception call stacks:


CLR exception type: System.Reflection.TargetInvocationException
    "Exception has been thrown by the target of an invocation."
*** ERROR: Symbol file could not be found.  Defaulted to export symbols for C:\Windows\system32\KERNELBASE.dll -
eax=0027eb88 ebx=00000005 ecx=00000005 edx=00000000 esi=0027ec48 edi=00000001
eip=7528812f esp=0027eb88 ebp=0027ebd8 iopl=0         nv up ei pl nz ac pe nc
cs=001b  ss=0023  ds=0023  es=0023  fs=003b  gs=0000             efl=00200216
KERNELBASE!RaiseException+0x54:
7528812f c9              leave
0:000> !loadby sos clr
0:000> !sos.PrintException
Exception object: 136eb7f8
Exception type:   System.Reflection.TargetInvocationException
Message:          Exception has been thrown by the target of an invocation.
InnerException: System.ArgumentException, Use !PrintException 136e9f10 to see more.
StackTrace (generated):
    SP       IP       Function
    00000000 00000001 mscorlib_ni!System.RuntimeMethodHandle.InvokeMethod(System.Object, System.Object[], System.Signature, Boolean)+0x2
    0033BEC8 60D99BC1 mscorlib_ni!System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(System.Object, System.Object[], System.Object[])+0xc1
    0033BEEC 60D904B6 mscorlib_ni!System.Delegate.DynamicInvokeImpl(System.Object[])+0x76
    0033BF00 6079C5BD WindowsBase_ni!System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate, System.Object, Int32)+0xad
    0033BF20 6079C49A WindowsBase_ni!MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(System.Object, System.Delegate, System.Object, Int32, System.Delegate)+0x3a
    0033BF64 6079EE4C WindowsBase_ni!System.Windows.Threading.DispatcherOperation.InvokeImpl()+0xac
    0033BF9C 6079ED88 WindowsBase_ni!System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(System.Object)+0x38
    0033BFA4 60E14157 mscorlib_ni!System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)+0xa7
    0033C010 60E14096 mscorlib_ni!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)+0x16
    0033C024 60E14051 mscorlib_ni!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)+0x41
    0033C03C 6079EC9B WindowsBase_ni!System.Windows.Threading.DispatcherOperation.Invoke()+0x5b
    0033C074 6079B21B WindowsBase_ni!System.Windows.Threading.Dispatcher.ProcessQueue()+0x16b
    0033C0B8 6079B3DA WindowsBase_ni!System.Windows.Threading.Dispatcher.WndProcHook(IntPtr, Int32, IntPtr, IntPtr, Boolean ByRef)+0x5a
    0033C104 6079C75B WindowsBase_ni!MS.Win32.HwndWrapper.WndProc(IntPtr, Int32, IntPtr, IntPtr, Boolean ByRef)+0x9b
    0033C140 6079C6AB WindowsBase_ni!MS.Win32.HwndSubclass.DispatcherCallbackOperation(System.Object)+0x6b
    0033C150 6079C562 WindowsBase_ni!System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate, System.Object, Int32)+0x52
    0033C170 6079C49A WindowsBase_ni!MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(System.Object, System.Delegate, System.Object, Int32, System.Delegate)+0x3a
    0033C1B4 6079AABE WindowsBase_ni!System.Windows.Threading.Dispatcher.LegacyInvokeImpl(System.Windows.Threading.DispatcherPriority, System.TimeSpan, System.Delegate, System.Object, Int32)+0x10e
    0033C208 6079BFF1 WindowsBase_ni!MS.Win32.HwndSubclass.SubclassWndProc(IntPtr, Int32, IntPtr, IntPtr)+0xf1
    00000000 00000001 System_Windows_Forms_ni!System.Windows.Forms.UnsafeNativeMethods+IMsoComponentManager.FPushMessageLoop(IntPtr, Int32, Int32)+0x2
    0033C4D8 5C35DFC7 System_Windows_Forms_ni!System.Windows.Forms.ComponentManagerProxy.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr, Int32, Int32)+0x27
    0033C4F0 5BBBF8D1 System_Windows_Forms_ni!System.Windows.Forms.Application+ThreadContext.RunMessageLoopInner(Int32, System.Windows.Forms.ApplicationContext)+0x155
    0033C540 5BBBF742 System_Windows_Forms_ni!System.Windows.Forms.Application+ThreadContext.RunMessageLoop(Int32, System.Windows.Forms.ApplicationContext)+0x4a
    0033C56C 5BB67004 System_Windows_Forms_ni!System.Windows.Forms.Application.DoEvents()+0x18
    0033C574 0682B972 MyAddin!Initialize()+0x6fa

StackTraceString: <none>
HResult: 80131604

The InnerException shows the initial exception throw:

0:000> !PrintException 136e9f10
Exception object: 136e9f10
Exception type:   System.ArgumentException
Message:          Illegal characters in path.
InnerException:   <none>
StackTrace (generated):
    SP       IP       Function
    0033BA18 617FFD07 mscorlib_ni!System.IO.Path.CheckInvalidPathChars(System.String, Boolean)+0xa68db7
    0033BA28 60E05936 mscorlib_ni!System.IO.Path.GetExtension(System.String)+0x16
    0033BA40 6D60F8E7 Microsoft_VisualStudio_Shell_UI_Internal_ni!Microsoft.VisualStudio.Services.VsImageService.GetIconForFileEx(System.String, Microsoft.VisualStudio.Shell.Interop.__VSUIDATAFORMAT, Microsoft.VisualStudio.Shell.Interop.__VSIconSource ByRef)+0x3f
    0033BA64 6D60F88C Microsoft_VisualStudio_Shell_UI_Internal_ni!Microsoft.VisualStudio.Services.VsImageService.GetIconForFileEx(System.String, Microsoft.VisualStudio.Shell.Interop.__VSUIDATAFORMAT, UInt32 ByRef)+0x14
    0033BA74 16D5ABD8 Microsoft_VisualStudio_Platform_WindowManagement_ni!Microsoft.VisualStudio.Platform.WindowManagement.UtilityMethods.GetDocumentTabImage(System.String, Microsoft.VisualStudio.Shell.Interop.__TABIMAGEFLAGS ByRef)+0x38
    0033BA90 6DE8F8F6 Microsoft_VisualStudio_Platform_WindowManagement_ni!Microsoft.VisualStudio.Platform.WindowManagement.WindowFrame.UpdateDocumentIcon()+0x131e2a

StackTraceString: <none>
HResult: 80070057

One known cause of this is to have embedded quotation marks in the document name. Example C# code which demonstrates the inner exception is as follows:

static void Main(string[] args) { string path = null; path = @"A09F9925-32BC-47E1-9DC0-1F71C64E9A6E@SAMPLE.""ADEFUSR0"""; string extension = System.IO.Path.GetExtension(path); }
This code will throw the System.ArgumentException on the GetExtension call.

↑ Back to the top


Keywords: kb

↑ Back to the top

Article Info
Article ID : 2923556
Revision : 1
Created on : 1/7/2017
Published on : 6/26/2014
Exists online : False
Views : 409