Tag Archives: mshtml

A bug in embedded Internet Explorer in Windows 8

Long-time readers of this site may remember that I did some work on embedding Internet Explorer, and its core rendering component MSHTML, in .NET applications. The code is still online.

I noticed that it does not work properly in Windows 8 Consumer Preview. Specifically, plain HTML works but you can no longer apply external CSS stylesheets. I reported the bug here (sign-in required).  I did not use my own component, but rather the standard WebBrowser control. I have appended the code to reproduce the bug in case you cannot see the report.

Microsoft has now responded as follows:

We were able to validate your feedback. However, based on the limited impact this bug may have, we will not be able to address this bug during this release.

This status is also known as “won’t fix” and gives me pause for thought. How many other little bugs are there which Microsoft is not fixing, but which break a certain number of applications?

If you are one of those few people using embedded IE in an application, I suggest checking Windows 8 compatibility now to avoid any unpleasant surprises.

Perhaps it would be preferable to use WebKit or Gecko (Mozilla) rather than IE in any case. There is a thread on stackoverflow that discusses some options. OpenWebKitSharp looks promising.

Code to reproduce the bug:

Create a Windows Forms application in C# in VS 11. Add a Webbrowser control and two buttons, and an OpenFileDialog control. Also add a reference to the COM library Microsoft HTML Object Library.

Here is the code for the first button that loads some HTML:

string sHTML = "<html><head><title>Some title</title></head><body><p>Some text</p></body></html>";
this.webBrowser1.DocumentText = sHTML;

Here is the code for the second button that applies a stylesheet:

openFileDialog1.Filter = "CSS files|*.css";
if (openFileDialog1.ShowDialog() == DialogResult.OK)  {
mshtml.HTMLDocument doc = (mshtml.HTMLDocument)this.webBrowser1.Document.DomDocument;
doc.createStyleSheet(openFileDialog1.FileName);
}

This is the stylesheet I am applying:

body
{
    font-family: Arial;
    font-size: 18pt;
}

To reproduce, run the application. Click the first button to load the HTML. Then click the second button to apply the stylesheet. In Windows 7 and earlier the stylesheet is applied. In Windows 8, the stylesheet is not applied.

UPDATE: It seems this bug was fixed in Windows 8 RTM, despite the “will not fix” designation. Good.