First tests using winform with IE8 showed that we the winform was opened, IE8 crashed
It was possible to open the winform with IE8 in compatibility mode, however this is not the native mode of IE8
I had a closer look to what happened:
- It seems that IE8 requires the dll Microsoft.mshtml.dll (in version 7.0.3300.0) to be present on the user’s computer when opening a web page embedding a winform control (even for a simple winform control this dll is required).
- Because of the following code in class UserControlBase when the winform is opened in IE8 on a computer where this dll is not present, the event AssemblyResolve is fired (because the dll could not be found). This code then tries to reload this assembly but this fires the AssemblyResolve event and a new attempt to load this dll is made … and so on …. And after more than 200 attemps IE8 crashes because of a stack overflow
public UserControlBase()
{
_currentBaseUserControl = this;
InitializeComponent();
AppDomain currentDomain = AppDomain.CurrentDomain;
currentDomain.AssemblyResolve += new ResolveEventHandler(AssemblyResolveEventHandler);
}
private System.Reflection.Assembly AssemblyResolveEventHandler(object sender, ResolveEventArgs args)
{
return System.Reflection.Assembly.Load(args.Name);
}
- This code has been added at the beginning of the project because we sometimes had problems opening the winform. A Microsoft consultant who helped us during this rewriting added this code and this fixed these problems.
This dll is part of the .Net 2.0 SDK; so it will be complicated to install this on the users’ computers so that they have this dll on their machines.
We have found that when the Microsoft.mshtml.dll (of version 7.0.3300.0) is present in the /res folder of the web site (along with the winform dlls), when this dll is “needed” by IE8 for opening the winform it is downloaded from the res folder of the web site and the event AssemblyResolve was not fired anymore(which fixes the IE8 compatibility issue).
To make winform compatible with IE8 we just need to place Microsoft.mshtml.dll (of version 7.0.3300.0) in the res folder of the web site.