Skip navigation

Daily Archives: June 19th, 2007

Author: Jeff Noble

Problem

I have found that navigating a webbrowser control to a sharepoint site causes the hosting program to crash when the host is closed. It doesnt matter if you navigate away or navigate to about:blank. If you visit a Sharepoint site and then end the application, the application will hang for several seconds in the task list and then crash. If you visit a Moss site (new Sharepoint) and then close the application it crashes immediatly.

Here is the repro code:

private void Form1_Load(object sender, EventArgs e)
{
webBrowser1.Url = new Uri(“
http://www.wssdemo.com/default.aspx”);
}

Just run the program, and let the site fully render, then close the application and viola:


The Fix

The crash is happening while unloading the NAME.dll which is used to show presence information. The crash happens when the client machine is running Office 2003.

Also, noticed that crash happens even if the presence information is turned OFF. The Name control is being rendered in both the cases. The crash is happening while unloading the NAME.dll which is used to show presence information. The crash happens when the client machine is running Office 2003. Also, noticed that crash happens even if the presence information is turned OFF. The Name control is being rendered in both the cases.

To Fix it, you pInvoke the ole32.dll so that you can call CoFreeUnusedLibraries(). Add the following to your class:

[DllImport("ole32.dll")]
static extern void CoFreeUnusedLibraries();

Then add this to the FormClosing event:

private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
webBrowser1.Navigate(“about:blank”);
System.Windows.Forms.Application.DoEvents();
CoFreeUnusedLibraries();
}

Thats all there is to it!

If I find any other information, I will post it.

-Savij

Follow

Get every new post delivered to your Inbox.