Skip navigation

It’s been a while since I posted, but it doesn’t mean I have not been busy. My latest endeavor has been putting a new side business together. I am just getting to the beta test phase and I am going to be tweaking 1.0 while I start on 2.0.

The site is called Share Your Deal. It’s a web site where you can share and search car prices posted by other users. Of course right now it just went live, so it has one whole car listed in it’s database, but that’s not the point. The point is it’s almost ready for prime time. The idea of the site is that people who get a good deal on a car in your area, can share the details of their deal so others can benefit from the information.

You can visit the site and help me debug it and tweak it by visiting www.shareyourdeal.com. Let me know what you think by sending me some email (contact us is at the bottom of the page).

Enjoy!

-J

I know, it’s been a long time since I updated this blog. I try my best to only put things here that really stump people (including me).

The Problem

Well, I was working on a WinForms project in c# which hosted a dialog with a  .net Browser control in it. That control was pointed to an aspx page which hosted a Silverlight plug-in.

The Silverlight ran perfectly! If by perfectly I meant that I only used it once or twice. After a few pops of my dialog, I got the following error:

scripterror

What the fuck was this?!? I put in error trapping …. still happened. I put in try catches in the JavaScript in the hosting page …. still happened!

The Solution

It turns out that I have seen something like this before, but where? Here is my thought process that triggered my memory. I noticed that the browser was not showing me my custom loading screen (or the default one once I took the custom one out). So, since the browser was not even downloading the xap file the problem was probably not mine. After all, it works the first few times but then wont even load the xap? Hmm, where have I seen this before?

So there is this awesome site that helped me with SharePoint crashing my browser control (oh wait that was this site <grin>). The problem was memory not getting released at the COM level in the browser control. It didn’t happen all the time and it didn’t happen on every win form, but it was consistent enough. The fact that the Silverlight would load and run just fine the first few times made me think that maybe the browser was getting tripped up on the Silverlight control and not releasing it’s hooks. Turns out that was the case!

Here is the fix:

Import the dll that holds CoFreeUnusedLibraries(), put this code at the top of your class just under the class declaration:

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

Hook your FormClosing event (or some event you can call when closing your view) and do this:

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

I added a call to Navigate so that the browser clears any current handles it might have and call DoEvents() just to give the browser a chance to clear out everything. You don’t see the browser change because it’s closing anyway.

That’s it! problem solved. Now wasn’t that worth the wait?

Here is a link to the previous post for more information if you like:

http://savij.com/2007/06/19/webbrowser-control-and-sharepoint-crash-at-close/

Follow

Get every new post delivered to your Inbox.