I have a custom Visual Studio project type which I am working on and quite recently I had a small issue which was self-inflicted i.e. not by Microsoft. I just thought I’d write out my experience for anyone who may have come across the same issue.
The issue was that I could not create/add the custom project more than once in an instance of Visual Studio. An exception would be thrown in the MPF (Managed Package Framework) when calling Marshal.CreateAggregatedObject(aggregateProjectIUnknown, newProject) inside the following method:
Microsoft.VisualStudio.Shell.Flavor.FlavoredProjectFactoryBase. PreCreateForOuter(IntPtr outerProjectIUnknown, out IntPtr projectIUnknown)
The exception message was: “The object already has a CCW associated with it. Parameter name: o” After googling around, I came across one other mention of this problem: http://forums.msdn.microsoft.com/en-US/vsx/thread/7f92445c-2d37-4f59-945f-7322a57bc53a/. Basically, as far as I understand our ProjectFactory creates a managed object of type ProjectContainerNode to represent our custom project. Thereafter when the above method Marshal.CreateAggregatedObject gets called it attempts to create a CCW (Com Callable Wrapper) for the managed object. This worked fine the first time, but the second time around when attempting to create/add another custom project it would throw the above exception.
The issue seemed to be in the ProjectFactory where we wrote the code to only create a new instance of the ProjectContainerNode if it was null. However, only a single instance of the ProjectFactory exists for each Visual Studio instance and therfore the ProjectContainerNode would never be null again after the first time the custom project was created. Therefore instead of a new project node being created, the MPF would be given the existing ProjectContainer node to which it had already created a CCW. The solution was to simply create a new instance of the ProjectContainerNode every time in my ProjectFactory.
4 Comments so far
Leave a comment
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <pre> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>
Your blog is interesting!
Keep up the good work!
Comment by Alex August 17, 2008 @ 9:41 amThanks Alex.
Comment by Paul Kolozsvari August 23, 2008 @ 8:48 pmKeep it up!!!!!
Comment by Josif Kolozsvari March 13, 2009 @ 10:05 amMersi
Comment by Paul Kolozsvari June 20, 2009 @ 6:42 pm