Debugging Exceptions thrown by Visual Studio Extension
Asked Answered
R

4

6

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.

Ramsey answered 12/9, 2016 at 7:38 Comment(0)
B
5

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.

Briggs answered 17/9, 2016 at 0:34 Comment(1)
Thanks for the clarification. I'll try forcing cache rebuild next time this happens.Ramsey
M
10

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.

Malaria answered 13/10, 2016 at 16:24 Comment(2)
Doesn't it affect only the experimental instance?Ramsey
@AmirGonnen Yes, but the screenshot in the question shows that the Experimental Instance is being used (14.0Exp\ActivityLog.xml), so it's a reasonable answer.Vulgate
B
5

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.

Briggs answered 17/9, 2016 at 0:34 Comment(1)
Thanks for the clarification. I'll try forcing cache rebuild next time this happens.Ramsey
S
2

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.

Stinky answered 12/9, 2016 at 12:18 Comment(2)
@Amir Gonnen, what about this issue? Would you please share the latest information about it?Stinky
I've updated the answer. If the problem ever comes back, I'll try out your suggestions. Thanks.Ramsey
P
-1

I solved the problem by deleting every relevant directory in <user>\AppData\Local\Microsoft\VisualStudio\

(The 'lower level' reset call didn't work because it couldn't find the directory blahblah\15.0Exp\. )

Btw, I use VS2017RCUpdate3.

Pinnatipartite answered 27/2, 2017 at 6:21 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.