Archive for October, 2008

Post

Hashtables and .Net Web Services

In .Net on October 21, 2008 by Matt Grande Tagged: , , , ,

If you’ve spent any time with .Net Webservices, you’ve probably seen this error:

System.NotSupportedException: The type System.Collections.Hashtable is not supported because it implements IDictionary.

Recently my co-worker Chelsea and I devised a way to get around this.  Hashtables are essentially collections of DictionaryEntrys with some extras to make certain functions.  So, all you have to do is convert from a Hashtable to a List<DictionaryEntry>.  Here’s how:

private static List<DictionaryEntry> ConvertHashToDictionaryEntryList(Hashtable source)
{
    var resultList = new List<DictionaryEntry>();

    foreach (DictionaryEntry item in source)
        resultList.Add(item);

    return resultList;
}

Hope this helps!  Happy coding.