Skip navigation

Monthly Archives: June 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

Author: Jeff Noble

The Problem

While working on a project, I wanted to have my partial class files that I created to be indented in the solution explorer under their dependant classes. The same way that a Form or UserControl makes a child node in the tree for it’s .designer.cs and .resx files.

When adding my own files, I could not figure out how to indent them. While searching, I found two solutions.

The Solution

You can edit the project file <yourproject>.csproj. To make a cs file a dependent, find the file you want to be the parent. It should look this this (your file name will be different of course):

<Compile Include=”Views\CallCenterView\CallCenterViewPresenter.cs” />

(yours may or may not include a SubType node, it doesnt matter).

Then find the line that holds the one you want to be the child file:

<Compile Include=”Views\CallCenterView\CallCenterViewPresenter.Order.cs”/>

Then add the <DependentUpon> node to the mix on the child nodes ONLY. Like this:

(Replace the above child line with the following)

<Compile Include=”Views\CallCenterView\CallCenterViewPresenter.Order.cs”>
<DependentUpon>CallCenterViewPresenter.cs</DependentUpon>
</Compile>

You can add as many of these as you like. Save and refresh the project in the VS IDE and you will see your efforts.

I also found this code posted on a forum and I HAVE NOT TESTED IT!! USE IT AT YOUR OWN RISK (but it looks safe at first glance).

This comes from bdaniel7 on the microsoft forums.

The code below is from an add-in I developed, add-in which generates some files and adds them to a C# project and makes them dependent of the file they were generated from. I’m using it in VS 2005 Pro and it works wery well. Create a new Add-in project in VS 2005 and you’ll see what are all classes presented here (DTE2, Project and so on); Of course, you can refine this example further…:P
private AddFileToProject( string tempFileName, bool ask )
{
    private DTE2 _applicationObject;
    Project currentProject =
    _applicationObject.SelectedItems.Item( 1 ).ProjectItem.ContainingProject as Project;
    localFile = Path.Combine(
        Path.GetDirectoryName( currentProject.FullName ),
        Path.GetFileName( tempFileName ) );
    bool localFileExists = File.Exists( localFile );
    if ( !ask ||
    (ask && !localFileExists) ||
    ( ask && localFileExists && ShowOverwriteDialog( localFile ) == DialogResult.Yes ) )
    {
        // copy the file in the project directory
        File.Copy( tempFileName, localFile, true );
        // add to project
        ProjectItem item = _applicationObject.SelectedItems.Item( 1 ).ProjectItem;
        // add as “DependentUpon”
        item.ProjectItems.AddFromFile( localFile );
        // expand the files below the selected item
        item.ExpandView();
        // save the project
        currentProject.Save( currentProject.FullName );
    }
}

bdaniel7

Follow

Get every new post delivered to your Inbox.