Getting rid of an AL1703 warning

Yesterday I was converting an old work-related project to the new csproj structure (using this very helpful tool by Hans van Bakel). Tackling compilation warnings one by one, I was finally left with this one:

Warning AL1073 Referenced assembly 'mscorlib.dll' targets a different processor

Some Googling revealed that this was related to .resx files and x64 platform targeting. Unfortunately, the workarounds offered on Stack Overflow didn't quite work for me. The warning was replaced by two warnings. The original one, plus this:

More...

Redux-connected React components in TypeScript

When I originally started using React together with TypeScript, I felt it was a great marriage of technologies. However, adding Redux into the mix (which is awesome, BTW) has created a lot of complexity to properly type my React Components. Type inference doesn't appear to work smoothly for the connect method in React Redux.

For simple stateless components, there is a pretty good solution by Silvio J. Gutierrez, which is pretty similar to something I had been using.

I've tried to come up with a good solution for more complex components as well. This is the best I've managed so far:

More...

Auto-configuring mail clients

Although I tend to prefer Microsoft .NET for my programming projects, I've used a large number of programming languages throughout the years. Last weekend I did a minor project in PHP for a change.

It involves helping users to configure their mail clients pretty much automatically. Outlook combined with Exchange does this really nicely, but that functionality is not limited to Exchange. Or Outlook, for that matter. I've run my own Linux based mail server at home for years, and this little project makes things a little bit easier for users of that mail server.

If you're at all interested in this sort of stuff, check out the project on GitHub.

PS: yes, this is the first article in a long time. I've started several, but decided against them halfway through. I always write about fairly niche things, but sometimes it turns out to be a bit too niche :)

Now, I could have done all this stuff in .NET of course. I personally have ASP.NET running even on my Linux box. Since this was such a tiny project and would usually run on a Linux based mail server rather than a dedicated web server, I figured that using .NET Core or Mono would make it a bit too niche again. Besides, using PHP every now and them makes me appreciate .NET all the more.

Capturing method arguments on your fakes (using FakeItEasy)

There are many isolation frameworks around that make writing unit tests relatively simple. It's highly unlikely that any single framework will meet all your needs, so writing your own utilities can be useful in order to make your tests easier to write and – perhaps more importantly – read.

I regularly find myself wanting to verify that a certain dependency is called in the right way by my system under test. This includes passed argument values, which can be complex objects themselves.

More...

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...

XapReduce: Optimizing Modular Silverlight Applications

Even though Silverlight has fallen out of grace with the powers that be, there are still some companies using it today for entertainment or line of business applications. Particularly for that last category, modularity can be a powerful tool in creating a flexible solution.

Over the past few years, I've worked with modular Silverlight applications based on Microsoft Prism. Every module is it's own XAP file, which is loaded on demand by the framework. Over the years, people have also rolled their own lightweight modular applications, also making use of XAP files. This article is about a specific problem with building these types of applications: optimization of the total application download size.

More...

Advanced base constructor calls in C#

Note: This article was edited after a Gonçalo Lopes presented me with a better solution. Thanks!

Every now and then you run into a situation where you wish your programming language of choice was just a tad more flexible than it actually is. For example, constructors in C# always have to directly call one of the base type constructors as the first thing they do (or do they? keep reading).

Yesterday I ran into a situation where I would like my derived class to always use the same implementation* for a certain injectable dependency. No problem:

public class FooBase
{
    public FooBase(IDependency dependency)    { /* stuff here */ }
}

public class MyFoo : FooBase
{
    public MyFoo() : base(new MyDependency()) { }
}

The dependency is created on the fly and my base class constructor is happy. However, my derived class also needed to make use of this dependency and my base class does not expose any property or field for me to access it. So before calling the base constructor, I would have liked to store a reference to this newly created MyDependency object.

More...

The CAPTCHA reinvented: PlayThru

The evolution of spam

Many blog owners will be familiar with one particular pest on the internet: spam bots. This blog is no exception, but I was determined to keep my pages clear of digital graffiti even when I don't have much time to post regularly.

Fortunately there are some nice and unobtrusive countermeasures available, like Akismet. They work pretty much like the spam detection for your email. For some time, this used to be enough to keep the spam bots at bay, but spammers are constantly changing their angle of attack. Many comments that are posted nowadays don't even contain any links anymore. With some luck, they can even pass for a comment from an interested reader. I'm not completely sure how exactly this helps the spammer, but no doubt they are trying to raise the reputation level of the IP address or email used to post the comment with, so t hey are more likely to pass through filters like Akismet later. In any case, spam filters are not as effective against these messages as they are against something containing one or more actual links.

More...

Updates to the Website

Just a quick note: I've updated the software for this website to BlogEngine.NET 2.8. Not a lot has changed since I've kept my original theme, but it does fix a few issues.

It also means that from now on you'll need to enter a CAPTCHA (provided by reCAPTCHA) in order to post comments. This is unfortunately necessary to stop excessive spamming that has been going for a while now. On BlogEngine 2.7 the reCAPTCHA plugin refused to work properly, but this seems to be fixed now.

If you happen to run into issues trying to post a comment – or anything else – drop me a note using the Contact form or on Twitter (@mveldhui). Also, authenticated users don't need to fill in a CAPTCHA for the moment, so you could also create an account. Thanks!