none
Default VSPackage template in VS2013 SDK Throws Exception when exiting

    Question

  • Hi,

    I have VS2013 Ultimate w/ VS2013 SDK, and have created a new C# VSPackage using Templates, Visual C#, Extensibility, .NET Framework 4.5, Visual Studio Package.

    When I hit "Start Debugging" and run in the Experimental Instance, and don't even click the Extension Menu Item at all, and just exit the experimental instance using File | Exit, I get this error:

    An unhandled exception of type 'System.Runtime.InteropServices.InvalidComObjectException' occurred in mscorlib.dll

    Additional information: COM object that has been separated from its underlying RCW cannot be used.

    Is this an expected error?  It happens while the extension is shutting down.

    Sunday, December 22, 2013 11:54 AM

Answers

  • This is, unfortunately, a known issue. It was introduced very late in the cycle and by the time it was found the CLR was already locked down to ship (they ship in Windows, so they are on a more aggressive schedule than us). Basically some debugging stuff the CLR added to do async causality tracing was/is using an RCW. During shutdown VS shuts down the CLR (we are a native app that custom hosts the CLR to run managed code), during that process the CLR instantly destroys all RCWs. If any code runs after that point and tries to use an RCW they get an InvalidComObjectException. This is what the CLR diagnostics code is trying to do. We pushed them to catch the exception since they need to deal gracefully with their RCW being disconnected in this scenario, but they wouldn't break escrow to take the change. I am not sure what their release schedule is for the fix, but you can ignore the exception (it annoys me too when I am doing package development :(). You can turn off breaking on that exception all together I believe, but there are times you want it (when other code is doing it it might be the sign of something bad).
    Tuesday, December 24, 2013 3:45 AM

All replies

  • Hi tballard,

    Please run visual studio with administrator. If it can not help you, I suggest you try breaking or use try-catch function to help you analyse this exception when it is thrown. If both of them cann't work, please check your code again and feel free to let us know.

    More information, please refer to http://stackoverflow.com/questions/4281425/how-to-avoid-a-system-runtime-interopservices-comexception

    http://msdn.microsoft.com/en-us/library/0yd65esw(v=vs.110).aspx


    Monday, December 23, 2013 10:21 AM
  • This is, unfortunately, a known issue. It was introduced very late in the cycle and by the time it was found the CLR was already locked down to ship (they ship in Windows, so they are on a more aggressive schedule than us). Basically some debugging stuff the CLR added to do async causality tracing was/is using an RCW. During shutdown VS shuts down the CLR (we are a native app that custom hosts the CLR to run managed code), during that process the CLR instantly destroys all RCWs. If any code runs after that point and tries to use an RCW they get an InvalidComObjectException. This is what the CLR diagnostics code is trying to do. We pushed them to catch the exception since they need to deal gracefully with their RCW being disconnected in this scenario, but they wouldn't break escrow to take the change. I am not sure what their release schedule is for the fix, but you can ignore the exception (it annoys me too when I am doing package development :(). You can turn off breaking on that exception all together I believe, but there are times you want it (when other code is doing it it might be the sign of something bad).
    Tuesday, December 24, 2013 3:45 AM
  • Thanks Ryan!
    Wednesday, December 25, 2013 12:10 PM
  • I created a new VSPackage using VS2013 Update 1 and this problem is still present.  Did they not ship the fix in Update 1?  Do you know when the fix will be shipped?  Is there a code change we can make in our projects to resolve this (i.e. it is a problem with the template)? or is this a bug in Visual Studio 2013 itself and we just have to wait for a product update that fixes the issue?

    Thanks.


    - Dan - "Can't never could do anything"


    • Edited by deadlydog Friday, February 21, 2014 6:44 PM
    Friday, February 21, 2014 6:43 PM
  • There is still not fixed in VS 2013 Update 2 either.

    This has to be the lowest of the totem pole on their priorities list.

    If anyone important had to encounter this error as many times as I do this would have been fixed a long time ago.

    Please fix this.


    Tuesday, June 03, 2014 7:28 AM