Adding a new ADO.NET Entity Data Model "Error HRESULT E_FAIL has been returned from a call to a COM component"
I tried adding a new ADO.NET Entity Data Model item to a VS 2010 solution, but I got this error message:
Error HRESULT E_FAIL has been returned from a call to a COM component.
It worked just a few days ago…hmmm….
I had another project open in another VS instance, and I had rebooted in the interim.
I tried a few other things, like using C#, VB, Console Application, rebooting and it still failed.
Here are the steps I was using:
1. Start VS.
2. File->New Project->C#/VB Console Application
3. Project->Add New Item-> ADO.NET Entity Data Model.
It turns out that the rebooting with the other project instigated the problem.
The other project had a Test project in it, and I had run some tests. I like to have the Test List Window and the Solution Explorer window tab docked. When rebooting, VS shut down and “remembered” the window positions, with the Test List window on top of (and thus hiding) the Solution Explorer window.
When creating a new project the Solution Explorer was still hidden. I invoked the Main Menu->Project menu->Add New Item, which attempted to invoke the wizard. The wizard tries to find the active project in the Solution window, but couldn’t find the Solution Explorer window, and thus the error message.
In fact, the problem can be reproduced by just starting VS with the Solution Explorer never having been created (or even hidden behind other docked windows).
More detailed repro step 1: Start VS: Close all Windows. Restart VS (so now only 1 window is open).
I was using Temporary projects, but apparently it doesn’t matter.
So, the simple fix is to make the Solution Explorer visible first. Many people right click on the project in the solution to add a new item, in which case this problem wouldn’t show.
The Visual Studio shell is a Win32 application that was originally written all in native C++ code many moons ago. With the advent of .Net over the years, more and more pieces are written in managed code.
Indeed, programmer productivity is substantially increased when writing in managed code, taking advantage of the .Net framework.
A simple example: how many ways can a string be represented in code? Managed code has a base String type, which is simple to use.
With native code over the years, there are many forms, like BSTRs, WSTRs, OLECHARS, CStrings, CATLStrings, etc. Each one of these has subtle semantic behavior differences, such as who is responsible for freeing the memory, whether null terminated or length prefixed, etc.
See also: Use temporary projects in Visual Studio
Comments
Anonymous
December 28, 2010
Similar to the ~2002 focus on fixing stack overflows holes in VS, MSCRT, etc, MS should consider a similar effort to replace as much COM based code with built in libraries either in .NET or win32.Anonymous
April 18, 2011
wow... I would have NEVER thought of this as a solution!!! i was completely convinced my installation is faultily... and I'm used to use Ctrl-Shift-A to add new items. Thanks a lot for sharing this... made my life easier.Anonymous
September 07, 2011
Can't believe it... Like Ahmad, I would NEVER have thought of this as a solution. I too was convinced that my installation was faulty and was contemplating a full reinstall. Thanks for the solution!!Anonymous
October 03, 2011
Thanks also for posting this solution. Add me to the list of contemplating a full reinstall.Anonymous
January 19, 2012
"So, the simple fix is to make the Solution Explorer visible first." That solved the problem on my system (using Visual C# 2010 Express on Windows 7). Thanks!Anonymous
May 30, 2012
The solution worked ... thank u so muchAnonymous
June 16, 2012
Thanks Calvin... This worked. Its amazing that I didnt know this after working for years on Visual Studio.Anonymous
July 24, 2012
Huh, who wouldv'e thunk it? Thanks so much, not only for the solution to a problem I NEVER would have figured out on my own, but for writing clearly enough, and with enough good keywords, that I was able to find your article quickly and easily amidst all of the Internet clutter!Anonymous
December 19, 2012
Thank you so much for the solution, I guess I should have expected this from MS, its really weird.Anonymous
October 31, 2013
Gracias por compartir este dato. Me ahorro muchísimo tiempo. En verdad muchas gracias por ayudar a otros.Anonymous
March 14, 2014
Thank you very much for the solution.Anonymous
November 05, 2014
Thank you so much. Add item rather than using the wizard will solve the problem. Many thanks!