Posts Tagged ‘Bug’

Extension Methods stop working!?

Wednesday, August 11th, 2010

I’m working on a solution where I have several different projects. Some of these projects are class libraries (DLLs) and some projects reference others. In some of them I have a number of extension methods.

I’ve noticed something strange happening occasionally. The extension methods in one of the class libraries stop functioning as extension methods for no apparent reason. This is even if they are called from within the same class library. It is usually after I have changed something, but not anything significant, and the namespace references all appear to be correct when I check. This isn’t just intellisense either – the build fails compilation.

The simple solution to this problem that I have found (which may solve other weird compilation bugs as well) is simply to clean the solution, close Visual Studio, reopen it and build again. This has worked every time that I’ve tried it so far.

This applies to Visual Studio 2010 Professional, and possibly 2008 as well, but I can’t remember if I had that problem then.

Unhandled exception clr20r3 mxyabj2rsfg4uknkgmspj2kfpmzxhcc5

Tuesday, August 3rd, 2010

A few weeks ago, I hit a problem that an application that I wrote suddenly started randomly dropping out with an unhandled exception. I can’t remember all the specifics anymore, but I do remember that the event that was written to the logs (that can be viewed in Event Viewer in Administrative Tools in Control Panel): –

EventType : clr20r3
P9 : mxyabj2rsfg4uknkgmspj2kfpmzxhcc5

The most confusing thing about this was that I have a system built in to the application to catch unhandled exceptions, and this had been working fine in the past for a few years. I couldn’t understand why it wasn’t catching this exception.

What was even more confusing was that it was randomly affecting several machines in different sets of circumstances. I eventually managed to find something that would reliably reproduce the problem, but when I tried it on my development PC in the debugger, it worked fine (I still haven’t worked out why this is).

I initially thought that maybe it was because I had just upgraded to Visual Studio 2010 and tried to back-convert my application back to Visual Studio 2008, but the problem continued. I also tried using remote debugging to track down the problem, which also caused a lot of problems as the application still seemed to be dropping out even with the remote debugger running!

I eventually tracked down the problem using a Try, Catch clause around code which I knew would reproduce the problem. The exception was about a missing resource file. I hunted around and eventually found that the resx file for the error handling dialogue window seemed to have been excluded from the project, presumably due to some bug while it was being upgrade to Visual Studio 2010.

After I put the resx file back, I was able to see that the application was throwing an exception. My code for dealing with the unhandled exception had caught it and been throwing the other exception, which didn’t have anything to catch it, so the Common Language Runtime (or Windows?) killed it.

Edit: The actual exception type that was being thrown was System.Resources.MissingManifestResourceException

Setting the .NET WebBrowser Control’s DocumentText Property

Tuesday, June 30th, 2009

The .NET framework comes with a nice WebBrowser control, which is a wrapper around MS Internet Explorer.  The problem is that it can be rather quirky at times, and one of these times is when you try to set the DocumentText property from code.  It might work, and then again it might not.  It is quite difficult to pin down exactly when it does work and when it doesn’t, but the following bit of code seems to set it for me…

  wbMsg.AllowNavigation = False
        wbMsg.AllowNavigation = True


        If wbMsg.Document Is Nothing Then
            wbMsg.DocumentText = s
        Else
            wbMsg.Document.OpenNew(True)
            wbMsg.Document.Write(s)
        End If

Windows Forms DateTimePicker ShowCheckBox and not Checked bug in .NET 2.0

Monday, March 9th, 2009

I recently upgraded a project that I had inherited from another programmer to .NET 2.0. Shortly after, I received an email complaining that a date field had stopped saving correctly. I tried it out, and all looked fine in the user interface, but sure enough, the value was not being written to the database.

It took me some time to work out what was going on. The ShowCheckBox property was set to False, but the Checked property also was. For some reason, the DateTimePicker in .NET 2.0 interprets this as meaning that the value that is in the control is to be ignored, and it returns today’s date if you access the Value property.

This was a pretty simple fix – all it took was to set Checked to True, and it all worked fine again. It is an interesting gotcha to look out for though – I haven’t seen it documented anywhere as a breaking change of .NET 2.0