18.8.08

Workaround - Visual Studio 6: Hang when trying to load a .cpp file

Ran into a brief problem today when working in VS6. I have a plugin set up to allow switching between .h and .cpp files. Today when I switched to a .cpp file, Visual Studio hung. Not sure if something else was amiss, I verified that I could load this file into another text editor (no file corruption). However, when I tried to directly load the .cpp file in VS, I received the same result.

Luckily, I am privy to the wisdom of co-author, TSE, with regards to vs6:

If all else fails, delete all non-essential project files: .plg, .ncb, .opt, etc. These pretty much are all autogenerated, and so worst case scenario is that stuff loads a bit slower. Best (and most often) case is that your mysterous VS6 bug will disappear along with the corrupted .dsw/.dsp support file.

In my case, it was the .opt that was hosed. It appears that Visual Studio was getting confused about which files remained open in the last session. (I kept getting a "Not all of the windows in the workspace could be opened." error). This information (or some other related information) must be stored in the .opt.

Suffice it to say that I'm back up and running. Thanks, TSE.

12.8.08

Explicitly Setting a Type's GUID with a C# Attribute

You may have noticed that every C# type has a "GUID" property of type Guid. If you don't explicitly specify, then this GUID is determined for you automatically. However, you can explicitly specify this GUID at compile time. We can thank COM interoperability for this ability, as setting an Interface's ID is essential, and so we can get this for our basic types as well. I personally like to use this ability for plugin object registration.

A couple "Using" statements for our example:

using System.Runtime.InteropServices;

using System.Diagnostics;

A dummy type with an explicit Guid using System.Runtime.InteropServices.GuidAttribute:

[Guid("7CB9C1E2-9BA4-4647-9202-FCFEF063552A")]

public class ExplicitTypeID

{

    public void CheckTypeID()

    {

        Debug.Assert

        (

            this.GetType().GUID ==

            new Guid("7CB9C1E2-9BA4-4647-9202-FCFEF063552A")

        );

    }

}

3.8.08

ExceptionBox: A reusable, user friendly Exception Dialog

exceptionbox_detailsexceptionbox_message The MessageBox class is sufficient for displaying errors, but not really a good solution. The problem is that there are multiple levels of information that is needed when displaying an error. What the end-user wants to see is something that is clean, understandable, and to the point. What the developer needs is all of the guts of the issue.

The ExceptionBox represents a happier medium between the two. The user-friendly message is displayed front and center, while the unfiltered guts are only a tab away. Add to that the ability to automatically copy all known details to the clipboard, and you have a solution that is much nicer than a standard MessageBox. I hardly ever code a .net application without it.

DevFuel.Core.UI.Forms.ExceptionBox is available in the DevFuel.Core.UI assembly of the devfuelnet project. To use the box, simply add a reference to the assembly, then call the Show() method. The using reference would be as follows:

using DevFuel.Core.UI.Forms;

using DevFuel.Core.UI;

Then you would catch your exception, and pass it to the ExceptionBox:

//Optionally set the default dialog icon

HostApplicationResources.DialogIcon = Properties.Resources.devfuel;

try

{

    Exception realException = new Exception("Ugly Exception");

    throw new Exception("User Friendly Message", realException);

}

catch (Exception x)

{

    ExceptionBox.Show(x);

}

HostApplicationResource simply represents the ability to set default icons and other details of the DevFuel Library. In the example, the devfuel icon is loaded from the assembly and displayed. If not specified, a generic icon is displayed.

Inner Exceptions and DevFuel's AggregateException (a wrapper for a collection of Exceptions) are all displayed and can be copied and pasted. I can't count the number of times this has saved me time. When a tester says they have a crash, and they copy and paste the details, this drastically improves my chances of finding the issue immediately. Meanwhile, the end user doesn't have to wade through debugging information in their dialog (unless they want to).

Full Source and downloads are available here.