Virtual events in C#

Yesterday I ran into an interesting (and dangerous) little detail about the C# compiler regarding virtual (field-like) events; they do not behave as you might expect. Consider this code, which I've simplified from a real world example of some refactoring gone wrong:

public abstract class MyClassBase
{
    public virtual event EventHandler<EventArgs> MyEvent;

    public void DoStuff()
    {
        if (MyEvent != null)
        {
            MyEvent(this, EventArgs.Empty);
        }
    }
}

public class MyClassDerived : MyClassBase
{
    public override event EventHandler<EventArgs> MyEvent;
}

To my surprise, when one subscribes to MyEvent, it will never be called:

More...

XapReduce 1.1

Last December I created a small utility to reduce the size of XAP files for modular Silverlight applications. It served my purpose at the time, but more recently I've been using the tool in the context of a new application, which revealed a problem related to localization. In some cases the application could crash because of satellite assemblies that are embedded into the XAP files.

The new version takes satellite assemblies into consideration: they are removed whenever the main assemblies is also removed. There are a small number of other issues that were fixed, like an incorrectly described command line parameter.

More...