Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Debugging Exceptions thrown by Visual Studio Extension

I'm running Visual Studio 2015 with some extensions.
I'm trying to debug the following error I'm getting:

An exception has been encountered. This may be caused by an extension

The errors are logged in ActivityLog.xml:

440 ERROR A MEF Component threw an exception at runtime: System.InvalidCastException: Unable to cast object of type 'System.Reflection.RuntimeMethodInfo' to type 'System.Reflection.ConstructorInfo'. 
  at Microsoft.VisualStudio.Composition.Reflection.ResolverExtensions.Resolve(ConstructorRef constructorRef) 
  at Microsoft.VisualStudio.Composition.RuntimeComposition.RuntimePart.get_ImportingConstructor() 
  at Microsoft.VisualStudio.Composition.RuntimeExportProviderFactory.RuntimeExportProvider.RuntimePartLifecycleTracker.CreateValue() 
  at Microsoft.VisualStudio.Composition.ExportProvider.PartLifecycleTracker.Create() 
  at Microsoft.VisualStudio.Composition.ExportProvider.PartLifecycleTracker.MoveNext(PartLifecycleState nextState) 
  at Microsoft.VisualStudio.Composition.ExportProvider.PartLifecycleTracker.MoveToState(PartLifecycleState requiredState) 
  at Microsoft.VisualStudio.Composition.ExportProvider.PartLifecycleTracker.GetValueReadyToExpose() 
  at Microsoft.VisualStudio.Composition.RuntimeExportProviderFactory.RuntimeExportProvider.<>c__DisplayClass15_0.<GetExportedValueHelper>b__0()   
  Source: Microsoft.VisualStudio.CommonIDE.ExtensibilityHosting.VsShellComponentModelHost 
  Time: 2016/09/12 07:16:43.932 
  
441 ERROR System.InvalidCastException: Unable to cast object of type 'System.Reflection.RuntimeMethodInfo' to type 'System.Reflection.ConstructorInfo'. 
  at Microsoft.VisualStudio.Composition.Reflection.ResolverExtensions.Resolve(ConstructorRef constructorRef) 
  at Microsoft.VisualStudio.Composition.RuntimeComposition.RuntimePart.get_ImportingConstructor() 
  at Microsoft.VisualStudio.Composition.RuntimeExportProviderFactory.RuntimeExportProvider.RuntimePartLifecycleTracker.CreateValue() 
  at Microsoft.VisualStudio.Composition.ExportProvider.PartLifecycleTracker.Create() 
  at Microsoft.VisualStudio.Composition.ExportProvider.PartLifecycleTracker.MoveNext(PartLifecycleState nextState) 
  at Microsoft.VisualStudio.Composition.ExportProvider.PartLifecycleTracker.MoveToState(PartLifecycleState requiredState) 
  at Microsoft.VisualStudio.Composition.ExportProvider.PartLifecycleTracker.GetValueReadyToExpose() 
  at Microsoft.VisualStudio.Composition.RuntimeExportProviderFactory.RuntimeExportProvider.<>c__DisplayClass15_0.<GetExportedValueHelper>b__0() --- End of stack trace from previous location where exception was thrown --- 
  at Microsoft.VisualStudio.Composition.RuntimeExportProviderFactory.RuntimeExportProvider.<>c__DisplayClass15_0.<GetExportedValueHelper>b__0() 
  at Microsoft.VisualStudio.Composition.DelegateServices.<>c__DisplayClass2_0`1.<As>b__0() 
  at System.Lazy`1.CreateValue() 
  at System.Lazy`1.LazyInitValue() 
  at System.Lazy`1.get_Value() 
  at Microsoft.VisualStudio.Text.Utilities.GuardedOperations.InvokeEligibleFactories[TExtensionInstance,TExtensionFactory,TMetadataView](IEnumerable`1 lazyFactories, Func`2 getter, IContentType dataContentType, IContentTypeRegistryService contentTypeRegistryService, Object errorSource)   
  Source: Editor or Editor Extension 
  Time: 2016/09/12 07:16:44.075 
  

Errors are reported with Source of Microsoft.VisualStudio.CommonIDE.ExtensibilityHosting.VsShellComponentModelHost and Editor or Editor Extension.

The errors do not mention which extension caused the error and I can't find any hints where to look for the problem.

When running with debugger (devenv.exe" /RootSuffix Exp) the debugger does not stop on the exceptions, and the error message box still appears.

Any idea how to further debug this, in order to find out which extension caused the problem and where in the extension the problem could be ?


Update

After closing Visual Studio, restarting the machine, re-installing an extension etc., the problem is gone.
I'm not happy about this, as I was not able to root-cause the issue or get any good hint where to look / how to debug this.

like image 611
Amir Gonnen Avatar asked Sep 12 '16 07:09

Amir Gonnen


3 Answers

Visual Studio 2015 Update 3 (at least) provides a start menu item:

Visual Studio 2015 > Reset the Visual Studio 2015 Experimental Instance

It seems to be lower level and simpler than the accepted answer: it calls

"C:\Program Files (x86)\Microsoft Visual Studio 14.0\VSSDK\
 VisualStudioIntegration\Tools\Bin\CreateExpInstance.exe"
 /Reset /VSInstance=14.0 /RootSuffix=Exp

which seems to just delete and recreate the relevant files.

like image 76
Mark Hurd Avatar answered Oct 30 '22 17:10

Mark Hurd


That error means that a cache in Visual Studio of extension information and the extensions you had installed got out of sync. It's not (likely) the fault of any extension itself, but rather a bug in Visual Studio. Make sure you're on the latest version with all updates installed -- we've fixed a few bugs in recent months that might cause something to go wrong. If you want to force the cache to be rebuilt, you can run:

devenv /updateconfiguration

To force the cache to be rebuilt on the next run.

like image 30
Jason Malinowski Avatar answered Oct 30 '22 15:10

Jason Malinowski


To make sure that whether it is related to the add-ins or extension tool, you can run your VS in safe mode:

devenv /SafeMode

If it works well in safe mode, we would think about them.

Based on the messages in your comments, I also didn't fine the error messages which share that which extension tool impacts the VS IDE.

Like this document here:

http://blog.masterdevs.com/debugging-a-visual-studio-crash/

You need to collect and view the detailed error messages like "which dll files or packages were not loaded or others", if you make sure that no other error messages, maybe you could clean the temp/AppData files, re-open your VS, check it again.

like image 26
Jack Zhai-MSFT Avatar answered Oct 30 '22 16:10

Jack Zhai-MSFT