Search code examples
visual-studiodebuggingvisual-studio-2015visual-studio-extensions

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.


Solution

  • 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.