Dictionary objects fail as long as the key is not of type string (or some base type)

XMLWordPrintableJSON

    • Type: Improvement
    • Resolution: Won't Fix
    • Priority: Minor - P4
    • None
    • Affects Version/s: None
    • Component/s: None
    • None
    • Environment:
      All
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      This method:

      public object CreateDictionary(Document document)

      { return document.ToDictionary(pair => (TKey)Convert.ChangeType(pair.Key, typeof(TKey)), pair => (TValue)pair.Value); }

      Will fail for all Dictionary types that have a key of any value other than string.
      This is because when the key of a dictionary is of some class type the key will be stored as the name of the class instead of a document.

      To replicate this behavior just create an object that contains a Dictionary<SomeCLRObject, SomeCLRObject> and save it.
      When you try to load it again you will get an error on CreateDictionary stating that (TKey)Convert.ChangeType(pair.Key, typeof(TKey) cannot be performed as string will not be cast to SomeCLRObject.

      I attached a sample to the SortedList bug that shows this behavior.
      http://jira.mongodb.org/browse/CSHARP-43

            Assignee:
            Craig Wilson
            Reporter:
            nisbus
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: