If you encounter this error (see below) when you try to Add Reference in Visual Studio:
The 'ReferenceManagerPackage' package did not load correctly. The problem may have been caused by a configuration change or by the installation of another extension. You can get more information by examining the file 'C:\Users\[UserID]\AppData\Roaming\Microsoft\VisualStudio\16.0_#####\ActivityLog.xml' Restarting Visual Studio could help resolve this issue. Continue to show this error message?
You can take a look at the ActivityLog.xml file, but most of the time it’s not necessary. Just for the sake of this example, let’s open it up:
<entry> <record>2479</record> <time>2021/03/12 01:21:02.715</time> <type>Error</type> <source>VisualStudio</source> <description>CreateInstance failed for package [ReferenceManagerPackage]Source: 'mscorlib' Description: Could not load type 'Microsoft.VisualStudio.Shell.Interop.IVsReferenceManager2' from assembly 'Microsoft.VisualStudio.Shell.Interop.11.0, Version=11.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.
System.TypeLoadException: Could not load type 'Microsoft.VisualStudio.Shell.Interop.IVsReferenceManager2' from assembly 'Microsoft.VisualStudio.Shell.Interop.11.0, Version=11.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.
 at System.Reflection.RuntimeAssembly.GetType(RuntimeAssembly assembly, String name, Boolean throwOnError, Boolean ignoreCase, ObjectHandleOnStack type)
 at System.Reflection.RuntimeAssembly.GetType(String name, Boolean throwOnError, Boolean ignoreCase)
 at System.Activator.CreateInstanceFromInternal(String assemblyFile, String typeName, Boolean ignoreCase, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes, Evidence securityInfo)
 at System.AppDomain.CreateInstanceFrom(String assemblyFile, String typeName)</description> <guid>{48D4A2C2-01AD-4F13-9123-610711CACB5B}</guid> <hr>80004005 - E_FAIL</hr> <errorinfo></errorinfo> </entry> </activity>
Or you can view it with IE or XML viewer:
For this particular case, Visual Studio cannot load Microsoft.VisualStudio.Shell.Interop.11.0.
There are several things you can try to solve this.
1. Delete ComponentModelCache Folder
- Exit all instances of Visual Studio.
-
Open File Explorer and go to %LocalAppData%\Microsoft\VisualStudio\16.0_##### folder and delete ComponentModelCache sub-folder.
- Restart Visual Studio with Admin privileges.
- Try to open your project and Add References.
If it works at this point, congratulations, but in my case, I got a slightly different error:
Error HRESULT E_FAIL has been returned from a call to a COM component.
2. Repair Visual Studio
This was suggested by many and it was the easiest to do, so it’s worth to try. Just launch your Visual Studio Intaller and select Repair from the More drop-down for the Visual Studio instance you want to fix.
I did not have any luck with this either. So I had to do the second step by reinstalling Microsoft.VisualStudio.Shell.Interop.11.0.dll using Global Assembly Cache Tool.
3. Reinstall DLL with Gacutil.exe (Global Assembly Cache Tool)
-
Open Developer Command Prompt for VS 2019 as administrator.
Make sure you see the word Administrator on the top of the command prompt window.
-
Go to the latest .NET Framework version folder you’re using (in this case it’s .NET Framework 4.8) to access the gacutil.exe file.
C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.8 Tools\x64>
-
Check where your DLL is located (your active Visual Studio instance). In this case, it is C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\PublicAssemblies folder.
-
Type in the following:
C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.8 Tools\x64>gacutil.exe /i "C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\Common7\IDE\PublicAssemblies\ Microsoft.VisualStudio.Shell.Interop.11.0.dll"
-
If it’s successful, you should see a message confirming that the assembly successfully added to the cache.
Check if any of the fix (or the combination of them), launch Visual Studio again, open your project and try to Add References again.
If successful, you should see Reference Manager window opened up.
References
“ReferenceManagerPackage” package did not load correctly VS 2019 community
How can I fix the Microsoft Visual Studio error: “package did not load correctly”?
Error HRESULT E_FAIL has been returned from a call to a COM component on Add Reference
Add a reference raise error: Error HRESULT E_FAIL has been returned from a call to a COM component
Gacutil.exe (Global Assembly Cache tool)
Irfan Usman. says
Point No. 4 worked for me. Thanks so much. God Bless You.
Seth Elorm Tudzi says
The last approach solved the problem for me. Am highly grateful for your help.
platt says
That’s great to know. Thanks for your feedback.