Easy fix for duplicate keys in a resource file (resx)

Today I was cleaning up some RESX files by doing some renaming (to conform to a naming conventions) and ran into the classic duplicate mnemonic problem that arise. With hundreds or thousands of mnemonic in a resource file this can become very time consuming. RESX files are not case sensitive which adds a little joy to the process…


I tossed together a utility that eliminates all of these duplicates and also sorts the mnemonics in the physical RESX file. This made reviewing a lot easier – so here’s the code in case you need it, just provide the folder holding the RESX files and you are done.


using System;
using System.Collections.Generic;
using System.IO;
using System.Xml;

class Program
    static void Main(string[] args)
        if (args.Length < 1)
        DirectoryInfo di = new DirectoryInfo(args[0]);
        foreach (FileInfo fi in di.GetFiles("*.resx"))
            XmlDocument dom = new XmlDocument();
            var list = new SortedList<string, XmlNode>();

            foreach (XmlNode node in dom.SelectNodes("//data[@name]"))
                var key = node.Attributes["name"].Value.ToLower();
                if (!list.ContainsKey(key))
                    list.Add(key, node);
            foreach (string key in list.Keys)


Popular posts from this blog

Simple WP7 Mango App for Background Tasks, Toast, and Tiles: Code Explanation

Yet once more into the breech (of altered programming logic)

How to convert SVG data to a Png Image file Using InkScape