Friday, 26 March 2010

MSMQ "The destination queue does not exist” or “BadDestinationQueue” when sending MSMQ messages or WCF net.msmq bound service calls

If you’re sending MSMQ messages using the DNS name of the server, you may get one of the above errors… this is easily fixed by adding a new registry key which tells MSMQ to ignore the hostname validation.

  1. Click Start, click Run, type regedit, and then click OK.
  2. Locate and then click the following key in the registry:


  3. On the Edit menu, point to New, and then click DWORD Value.
  4. Type IgnoreOSNameValidation, and then press ENTER.
  5. On the Edit menu, click Modify.
  6. Type 1, and then click OK.

See the Microsoft Support Article.

Wednesday, 24 March 2010 product feeds gzip trailer invalid / corrupt.

Please note that product feeds in gzip format are corrupt.  There is no CRC32 or ISIZE value in the trailer of the file which is required. Please see the gzip spec. You can see this by opening a valid gzip file and their invalid gzip file in WinRAR or 7-Zip… there’s no input file size or CRC in the file.
Also see

On a separate note; if you're looking for free online event registration and booking management, check out this website.

GZipInputStream, GZipStream, GZipUtil, C#.NET UNIX .gz files - decompression ends prematurely - Workaround

I have been trying for days now to decompress a 10MB gzip file using
  • ICSharpCode.SharpZipLib.GZip.GZipInputStream,
  • Ionic.Zlib.GZipStream,
  • and System.IO.Compression.GZipStream
Using both my own code and other people’s code from all over the Internet.  I have tried analyzing the file to make sure it’s valid – and it is. The only thing I know about this file is that it’s been compressed by a UNIX based system with the “DEFLATE” method, downloaded over http and can be successfully decompressed by 7Zip, WinZip and WinRAR.  But when it comes to decompressing the file within C# with various libraries, it’s just not happening.  It always prematurely ends the decompression, so I get a truncated file.
In the end, I decided to wrap a call to gzip.exe which can be downloaded from  or the direct Windows Download is here.
Put gzip.exe inside your project folder, in Solution Explorer and ensure “Copy to output directory” is set to “Copy always”.  The code for calling the exe is below.
/// <summary>
/// Uncompresses a gzip file 
/// </summary>
/// <param name="gzipFilename"></param>
/// <returns></returns>
public static string UngzipFile(string gzipFilename)
    const string GZIP_EXE_NAME = "gzip.exe";
    string gzipExePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, GZIP_EXE_NAME);
    string args = string.Format("-d \"{0}\"", gzipFilename);
    var p = System.Diagnostics.Process.Start(gzipExePath, args);
    return gzipFilename.Remove(gzipFilename.Length - 3, 3);

UPDATE: ok, the files I’m trying to decompress are corrupt – they have no ISIZE or CRC32 GZip File Trailer (well, they are zero, which can’t be good).  I wish there was a way to force it to decompress as the bandwidth usage for uncompressed it massive.

UPDATE MAY 2012: Turns out the GZip file is a multi-part BGZF "Blocked GNU Zip Format" file.  Basically, it's a file with multiple GZip files concatenated.  In order to support BGZF with GZipStream you must first pre-process the GZip file and strip out all the additional GZip file headers and footers... then concatenate all the compressed payloads. See:

Tuesday, 16 March 2010

How to horizontally centre align an inner div of unknown width within an outer div of known width :: CSS, JQuery, HTML.

Situation:  You have a an outer div with the id “outer” and an inner div called “inner”.  The menuCont div is of fixed width; let’s say 960 for this example.

The inner div contains variable width elements and you cannot know at design time how many elements and of what width they will be.  You cannot do this with CSS alone (but if you know how, please do share!)

Here’s the solution – it relies on jQuery BTW.

Set the CSS as follows:


And HTML as follows:

<div id="outer">
  <div id="inner" style=”display:none”>
    <!-- Insert variable width elements here -->

And then JavaScript:

$(document).ready(function() { = function() {
        return this.each(function() {
            var el = $(this);
            var w = el.width();
            var w_box = 960; // TODO: ADD THE CONTAINER WIDTH HERE!
            var w_total = (w_box - w) / 2;
            var css = { "position": 'absolute', "left": w_total + "px" };
$("#inner").fadeIn(); // optional! could use show()

This solution can definitely be improved – but it’s a start.

Monday, 15 March 2010

HttpModule and Application_Start

Unfortunately there is no “Start” event to hook onto for HttpModules.  Instead you should use Init() – be aware though that there may be multiple instances of your http module, serving many threads in the appdomain.  So you need a bit of thread sync’ing in order to ensure that your start-up code only executes once.

    public class MyHttpModule : IHttpModule
        /// <summary>
        /// Mutex object which gives the lock statement something to get an exclusive lock on
        /// </summary>
        private readonly static object _mutex = new object();
        /// <summary>
        /// Flags whether the application has started
        /// </summary>
        private static bool _isInitialised = false;
        #region IHttpModule Members
        public void Dispose()
        public void Init(HttpApplication context)
            if (!_isInitialised) 
                lock (_mutex)  
                    if (!_isInitialised) 
        /// <summary>
        /// Application start-up code will be executed once here
        /// </summary>
        private void Application_Start()
            _isInitialised = true;
            // add code

ASP.NET, JQuery, Colorbox, Postback Problem

As Colorbox appends inline divs to the body tag, this is outside the form.


Change this: $('body').prepend($overlay,  $cbox.append($wrap, $loadingBay))

To this: $('form').prepend($overlay, $cbox.append($wrap, $loadingBay))

or search in the minified file for “body”, and replace it with “form”.

I also recommend prepending the project name to the min file and putting a comment the top stating it’s been customised.

Friday, 12 March 2010

Umbraco, XSLT :: Reading RSS Feeds, Aggregating and Sorting

Here's a quick summary of how to read multiple RSS feeds, merge them, sort them and then output the first 30 items.  You can easily combine and concatenate nodes from external sources into an xsl:variable with xsl:copy-of and GetXmlDocumentByUrl.


  1. Set up a doc type named 'RssFeed' with a property called 'url' (textstring)
  2. Create RSS Feed nodes in the Content section with your chosen feed urls
  3. Create an XSLT macro with the code that follows.


Just put this into an <xsl:template> and it will output the first 30 items.

<!-- Find all RSS Feed nodes, create new XML tree with all rss nodes merged into the 'container' node -->
<xsl:variable name="rssFeeds">
    <xsl:for-each select="$currentPage/ancestor-or-self::root//node [@nodeTypeAlias='Feed Item']">
      <xsl:variable name="url" select="string(data[@alias='url'])" />
      <!-- Is the url populated? -->
      <xsl:if test="string-length($url) &gt; 0">
        <!-- Import the feed-->
        <xsl:copy-of select="umbraco.library:GetXmlDocumentByUrl( $url )"/>
<!-- Iterate through the container doc -->
<xsl:for-each select="msxsl:node-set($rssFeeds)/container/rss/channel/item">
  <!-- Sort the items -->
  <xsl:sort select="pubDate" order="descending"/>
  <!-- Only output the first 30 items -->
  <xsl:if test="position() &lt;= 30">
        <xsl:attribute name="href">
          <xsl:value-of select="link/text()"/>
        <xsl:value-of select="title/text()"/>
      <xsl:value-of select="description/text()" />