Uploaded image for project: 'C# Driver'
  1. C# Driver
  2. CSHARP-44

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

    XMLWordPrintableJSON

Details

    • Icon: Improvement Improvement
    • Resolution: Won't Fix
    • Icon: Minor - P4 Minor - P4
    • None
    • None
    • None
    • None
    • All

    Description

      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

      Attachments

        Activity

          People

            craig.wilson@mongodb.com Craig Wilson
            nisbus nisbus
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: