Answered by:
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).
- Edited by Ryan MoldenMicrosoft employee Tuesday, December 24, 2013 3:58 AM typo
- Marked as answer by tballard Wednesday, December 25, 2013 12:10 PM
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
- Edited by Anna Cc Monday, December 23, 2013 10:24 AM
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).
- Edited by Ryan MoldenMicrosoft employee Tuesday, December 24, 2013 3:58 AM typo
- Marked as answer by tballard Wednesday, December 25, 2013 12:10 PM
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 -
This issue is seem to be resolved in VS 2013 Update 3.
Friday, August 8, 2014 6:38 AM -
No, it is not resolved.
And it seems that the fix is required in the CLR of the .NET Framework, not in Visual Studio.
* My new blog about VSX: http://www.visualstudioextensibility.com * Twitter: https://twitter.com/VSExtensibility * MZ-Tools productivity extension for Visual Studio: http://www.mztools.com.
Wednesday, August 13, 2014 5:41 PM -
Yes, you are right. It is still there in Update 3.Thursday, August 14, 2014 8:39 AM
-
Is it fixed yet?Monday, November 3, 2014 9:16 PM
-
AFAIK no
* My new blog about VSX: http://www.visualstudioextensibility.com * Twitter: https://twitter.com/VSExtensibility * MZ-Tools productivity extension for Visual Studio: http://www.mztools.com.
Tuesday, November 4, 2014 9:18 AM -
It's a joke. Of course it's not fixed yet. :PTuesday, November 4, 2014 10:04 AM