Programming

Error HRESULT E_FAIL

Error HRESULT E_FAIL is a common error in VS that Microsoft is yet to address/fix. A fix I found on Visual Studio 2019 Version 16.2.4 (Updated Aug 2019).

One day I was in a project and I needed to add a reference to the current project and when doing so was presented with the following error:

 

Error HRESULT E_FAIL
Error HRESULT E_FAIL

 

 

 

 

 

 

HRESULT E_FAIL has been returned from a call to a COM component

I followed every single post online on how to fix this issue but they were all the same, not one post helped. I tried everything from a reinstall, cleaning the registry, deleting folders from ProgramData/AppData/ .vs Folder or even Program Files (x86), yet none of the issues help.

These are the steps that I’ve taken to add a reference to a project, even though it gets added, if I try to add a reference by right clicking and choosing the add reference I still get the same error!

 

          1. Press and Hold the following sequence in VS2019 Cntrl+Alt+J
          2. This opens the Object Browser
          3. Reviewing the image below click on the dots below the yellow dot

 

 

 

 

 

  1. You will now see a window that says Edit Custom Component Set

 

 

 

  1. All you need to do in the browse section is choose the reference

 

 

 

 

 

 

 

  1. Once you’ve specified the reference click on Add

 

 

 

 

 

 

  1. Now you’ve to click on Projects next to browse

 

 

 

 

 

 

  1. In this step all you need to do is click on Add again and then press ok
  2. You will now see in the list the reference you’ve added to your project and the name of your project.
  3. For the last step all you need to do is select the reference that you just added
  4. Now press the button below the red dot in the image below

 

 

 

 

  1. Add to References in Selected Project in Solution Explorer
  2. You will now get a message that you’ve added the reference to your current project, that’s it.

 

Summary

Even after going through all of those steps, if you still try and right click to add a reference, you still get the Error HRESULT E_FAIL has been returned from a call to a COM component error. I am surprised that after all this time Microsoft hasn’t fixed this issue. But the fix works from the current version. I did try using previous versions but since this is the latest I opted to use VS2019 instead.