Unit testing multi-threaded, asynchronous code and/or events

I’ve been writing some unit tests recently that test some multi-threaded functionality.

Typically this involves hooking up some event handlers then waiting for some asynchronous code to fire the event before proceeding with the unit test and assertions.

The ManualResetEvent class (MSDN) seems a good choice for this, and this post has a small example of using it . . . → Read More: Unit testing multi-threaded, asynchronous code and/or events

Could not load file or assembly ‘x’ or one of its dependencies. Strong name validation failed.

In some of the work I’m doing right now, I’m manipulating an assembly after compile time – having it disassembled into IL, tweaked, then re-compiled back into an assembly.

The assembly is signed and what is being done to the assembly is breaking the strong name. This is quite comforting to know; the strong name wouldn’t be . . . → Read More: Could not load file or assembly ‘x’ or one of its dependencies. Strong name validation failed.

Configuring NLog for your application when NLog is in the Global Assembly Cache (GAC)

If you have several applications that are using NLog, it can be a good idea to install NLog into the GAC and reference that.

A gotcha you must watch out for is caused by this piece of configuration from the NLog site:

<configuration>
<configSections>
<section name=”nlog” type=”NLog.Config.ConfigSectionHandler, NLog”/>
</configSections>
<nlog>
</nlog>
</configuration>

Because you are not using the strong name for the Assembly-qualified name of . . . → Read More: Configuring NLog for your application when NLog is in the Global Assembly Cache (GAC)

Creating thumbnail images with automatic cropping and maintaining aspect ratio

Most thumbnail-generation solutions will shrink the original down while maintaining aspect ratio.

Usually you specify the maximum height and width of the thumbnail, e.g. 150 x 200.

However, if your original image’s aspect ratio is different to the maximum thumbnail dimensions, you will end up with dead space vertically or horizontally (shown in green in the illustration). This can be quite an eyesore when displaying thumbnails in a grid.

Normal Thumbnail Resizing Diagram

I’ve got an algorithm that will automatically crop the image either horizontally or vertically to then match the thumbnail aspect ratio, so you end up with the thumbnails all being the same size even though they may be coming from originals of wildly different aspect ratio.

In the illustration, you can see that the image is scaled down and fills all the available thumbnail space, showing the parts in grey from the original that were cropped out.

Image resizing with automatic cropping

The algorithm does the cropping before the resizing. It takes the width and height of the original image, and the width and height of the desired thumbnail. It will return the width and height that the original must be cropped to, to match the aspect ratio of the thumbnail. Continue reading Creating thumbnail images with automatic cropping and maintaining aspect ratio

Castle Project update

Hamilton has applied a bunch of patches and fixes to the Castle Project for the Components and Windsor sub-projects. Including 2 minor and insignificant patches that I submitted +D. It’s good to feel part of a major Open Source project, even for a small contribution.

http://hammett.castleproject.org/?p=336

While I’m currently focusing my efforts on ASP.NET MVC and moved away . . . → Read More: Castle Project update