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