[Mono-bugs] [Bug 425693] New: Dictionary<K, V> cast as IDictionary doesn' t allow null values to be added/set

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Thu Sep 11 19:59:30 EDT 2008


https://bugzilla.novell.com/show_bug.cgi?id=425693


           Summary: Dictionary<K,V> cast as IDictionary doesn't allow null
                    values to be added/set
           Product: Mono: Class Libraries
           Version: 1.9
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: Normal
          Priority: P5 - None
         Component: CORLIB
        AssignedTo: mono-bugs at lists.ximian.com
        ReportedBy: jonbnews at hotmail.com
         QAContact: mono-bugs at lists.ximian.com
          Found By: Community User


If you have a Dictionary<K,V> that's cast to an IDictionary and attempt to add
a null value, or set a key to a null value, it throws the following exception:

System.ArgumentException : not of type:
Drms.Server.Oas.Persistence.Tests.ChildAObject
Parameter name: value
  at
System.Collections.Generic.Dictionary`2[System.String,Drms.Server.Oas.Persistence.Tests.ChildAObject].ToTValue
(System.Object value) [0x0003b] in
/tmp/mono-1.9/mcs/class/corlib/System.Collections.Generic/Dictionary.cs:588 
  at
System.Collections.Generic.Dictionary`2[System.String,Drms.Server.Oas.Persistence.Tests.ChildAObject].System.Collections.IDictionary.Add
(System.Object key, System.Object value) [0x00000] in
/tmp/mono-1.9/mcs/class/corlib/System.Collections.Generic/Dictionary.cs:601 

I believe the ToTValue method is not correct.  It's implemented like this:

TValue ToTValue (object value)
{
   if (!(value is TValue))
      throw new ArgumentException ("not of type: " + typeof (TValue).ToString
(), "value");
   return (TValue) value;
}

If value is null, then the "value is TValue" check fails.  It should have an
additional check for null.

A test case would be something like this:

System.Collections.IDictionary dict = new
System.Collections.Generic.Dictionary<string, string>();
dict.Add("foo", null);
dict["foo"] = null;

If it's not cast as an IDictionary, adding null values works fine.


-- 
Configure bugmail: https://bugzilla.novell.com/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.
You are the assignee for the bug.


More information about the mono-bugs mailing list