Skip navigation

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

Advertisement

9 Comments

  1. Thanks heaps Jeff! I’ve been experiencing the same problem as well.

  2. Fantastic fix! Worked perfectly. This issue has bugged us for over a year since we upgraded to WSS3.

  3. Thanks a lot, I’ve been experiencing this problem on production server and did not find any suitable solution for this.

  4. Many thanks. This a nasty problem. You saved the day. thanks.

  5. Thanks! works fine

  6. Is it possible to provide code for this solution in VB please? It would be greatly appreciated!

  7. Found similar solution for VB users:

    Private Declare Sub CoFreeUnusedLibraries Lib “ole32.dll” ()

    Private Sub Form_Unload()
    CoFreeUnusedLibraries
    End Sub

  8. We got a similar crashing issue when using WebBrowser and adobe reader 9 (latest liveupdate didn’t fix issue). And this thread helped me to fix my issue! THANKS

    Our Situation:
    We are using WebBrowser [axWebBrowser] in a c# .NET 1.1 Application to mainly display .pdf
    Most of the time.. user had the this error when closing our application:
    —————————
    sw: TestBrowserNET11.exe – Application Error
    —————————
    The instruction at “0x0700609c” referenced memory at “0×00000014″. The memory could not be “read”.
    Click on OK to terminate the program
    —————————
    OK
    —————————

    On my computer Rolling back to Adobe Reader 8 was fixing the issue but this was not an acceptable solution/workaroud

    Fix:

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

    protected override void Dispose( bool disposing )
    {
    if( disposing )
    {
    if(axWebBrowser != null)
    {
    if(axWebBrowser.LocationURL != “about:blank”)
    {
    axWebBrowser.Visible = false;
    axWebBrowser.Navigate(“about:blank”);
    }

    while(axWebBrowser.Busy)
    {
    Application.DoEvents();
    }

    CoFreeUnusedLibraries();

    axWebBrowser.Dispose();
    axWebBrowser = null;
    }

    if(components != null)
    {
    components.Dispose();
    }
    }

    base.Dispose( disposing );
    }

    I hope this could point you to a solution, even if some of you are directly using the Adobe ActiveX,
    thoose sites help me to find out what’s going one… thanks to all, and hope this reply can save time to others ;o)
    http://www.adobeforums.com/webx/.59b6a24b
    http://www.xtremevbtalk.com/showthread.php?p=1321672

  9. Fantastic!!!!!!!!!!!!!!!


One Trackback/Pingback

Leave a Reply

Fill in your details below or click an icon to log in:

Gravatar
WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.