34

I have a C# solution that makes use of Smith Html Editor (I'm developing on the main project which uses this, so I don't know much about this library), which makes a reference to MSHTML. This worked fine until my upgrade to Windows 10 and it can't find MSHTML anymore. I can directly reference the DLL on the GAC folder, and it stops complaining and thus builds, but it's getting some runtime errors related to the editor not instantiating.

After a little research, it turns out that MSHTML is phased out of Windows 10 as it now uses EdgeHTML. Does anyone have any idea how I can go around this?

The solution still works for Windows 7.

Tyress
  • 3,573
  • 2
  • 22
  • 45
  • Have you tried contacting the author of the html control? – Mark Jansen Aug 06 '15 at 10:47
  • 5
    It is not "phased out", MSHTML is still heavily used in Win10. The Winforms and WPF WebBrowser classes depend on it. Nothing is visibly wrong with the COMReference is that .csproj file. Try it out with a dummy project, use Project > Add Reference > Browse button and select c:\windows\system32\mshtml.tlb. If that falls over then you'll know something else you can document in your question. At a minimum quote *exact* error messages and mention the Path property value of the MSHTML reference. – Hans Passant Aug 06 '15 at 12:46
  • if my answer was helpful it would be great if you could flag my answer as correct. Thank you! – Malte Lantin Feb 29 '16 at 10:41
  • @Tyress Can we use this in Windows 10 UWP app? – Kinjan Bhavsar Apr 29 '16 at 11:29

8 Answers8

53

I just created a blog post on this issue. The problem is that the Microsoft.mshtml.dll assembly in the Global Assembly Cache becomes unregistered from ActiveX during the upgrade process. To fix this issue, it is necessary to run "regasm" on the assembly:

  1. Open an instance of "Developer Command Prompt for VS2013" (or whatever version of Visual Studio you happen to be using). Run it as Administrator by right-clicking the icon and selecting, "Run as Administrator."
  2. Navigate to "C:\Windows\assembly\GAC\Microsoft.mshtml\7.0.3300.0__b03f5f7f11d50a3a." It is possible your path will vary. To verify, go to "C:\Windows\assembly\GAC\Microsoft.mshtml" and type "dir."
  3. Once you are in the correct path, type regasm Microsoft.mshtml.dll
user1233749
  • 796
  • 6
  • 6
  • 5
    I've the same Problem after updating to Windows 10 (Ver. 1607) For me this solution worked fine. Thank you! – Tintifax Sep 22 '16 at 08:23
  • We had the issue that it wasnt event located in the GAC at all. We got it working by manually creating the mentioned folder structure first and then following these steps. – CSharpie Mar 08 '17 at 16:11
  • Thank you - this fixed exactly my problem after a Windows 10 update ! – bernhardrusch Nov 02 '17 at 15:35
  • 1
    I had this problem today, after Windows 10 Fall Creators Update. Your solution works great! – jeanie77 Jan 12 '18 at 13:45
  • 1
    Thanks, this solution worked for me after I had upgraded to Windows 10, Ver 1803, OS Build 17134.81 – sm2mafaz Jun 06 '18 at 01:28
  • In a clean install of Windows 11 it's not there at all! Need to use @Chris answer. You can search the gac with `gacutil.exe /l | find "Microsoft.mshtml"` first to confirm. This is most easily run in the Visual Studio command prompt. – Simon_Weaver Jun 15 '22 at 00:30
10

Great solution Aron!

In my case it was:

CD C:\Program Files (x86) [Enter]
CD Microsoft Visual Studio\2019 [Enter]
CD Community\Common7\IDE\PublicAssemblies [Enter]
gacutil -i Microsoft.mshtml.dll [Enter]
exit

(I wrote these on seperate lines since word-wrap made it confusing to read).

Chris Raisin
  • 384
  • 3
  • 7
  • 1
    Visual Studio is now 64 bit. As of VS 2022 today on a Windows 11 machine I found this in `C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\ide\PublicAssemblies` – Simon_Weaver Jun 16 '23 at 21:11
7

I had the exact same problem. Adding the c:\windows\system32\mshtml.tlb worked. Note it's NOT the dll, but the tlb. Thank you so much for asking this question and thank you Hans, for the answer :)

5

I had the same issue and I think what's going on, at least in my case, is that the project was originally a VS2012 project on Windows 7 and there was a primary interop assembly installed that was referenced. When I removed and re-added the reference to MSHTML and did a diff on the files, the only difference was that the <WrapperTool> was changed from primary to tlbimp and <EmbedInteropTypes> was changed from false to true.

At some point, Visual Studio added the ability to embed the COM wrappers directly into the assembly instead of referencing PIAs, so my guess is that a new VS2015 installation on Windows 10 no longer installs PIAs because they're not necessary. So that's why removing and re-adding the reference fixes the problem and the project should continue to build fine on older OS as well.

Josh
  • 68,005
  • 14
  • 144
  • 156
4

In case if all of the above failed to work for you, here's my solution which is different to the above and it worked for me:

I registered the microsoft.mshtml.dll in the global assembly cache.

Here is the solution:

Step 1: Open the Developer Command Prompt by typing dev in your windows 10 search box and right click the Developer Command Prompt for VSxxxx and run as administrator

Step 2: Navigate to your microsoft.mshtml.dll library. In my case:

CD C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\PublicAssemblies>

Step 3 Run the following command to register in the global assembly cache:

gacutil -i Microsoft.mshtml.dll

For more information visit this web article: https://learn.microsoft.com/en-us/dotnet/framework/app-domains/how-to-install-an-assembly-into-the-gac

3

MSHTML is still an important component in Windows 10, even with Edge as the default browser. You can find it in "C:\Windows\System32". To quote from the official FAQ:

http://dev.modern.ie/platform/faq/will-the-webbrowser-control-work-with-mi

MSHTML:

In Windows 10 the WebBrowser control will use Internet Explorer’s legacy rendering engine, mshtml.dll. At this time EdgeHTML is not available through the WebBrowser control.

EdgeHtml

In Universal Windows Apps built for Windows 10, the WebView control use Microsoft EdgeHTML. WebView controls in apps built for Windows 8 & 8.1 will continue to load the MSHTML to preserve compatibility.

Malte Lantin
  • 346
  • 1
  • 8
2

For some reason in my case the Microsoft.mshtml file was located in a different directory. On Visual Studio, double click the assembly reference, and you'll find the path to it. Now open the "Developer Command Prompt for VS2017", type the following cd C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\PublicAssemblies. Then regasm Microsoft.mshtml.dll.

1

Using VS 2015 I had this issue after the last Windows 10 update. I removed the reference "Microsoft HTML Object Library" and added it again to the project. This resolved the issue in my case.

Wolf
  • 11
  • 2