1
Vote

Parameter count mismatch serializing a Dictionary

description

Hi,
 
I use DynamiteXML on my http:// NFileStorage.codeplex.com project, and it works like a charm, however I did find a bug.
 
I have made a class X that implements the IDynamiteXML interface. It contains a SerializableDictionary property
(Note that the 'default' Dictionary is not Serializable... see http://weblogs.asp.net/pwelter34/archive/2006/05/03/444961.aspx for the one I use).
 
When I serialize an instance of class X an Exception is thrown in the method, at the last line of;
 
private static void evaluateAllStringProperties(object obj, serializingMode serializingMode)
    {
        if (obj != null)
        {
            foreach (PropertyInfo pi in obj.GetType().GetProperties())
            {
                if (!(pi.PropertyType == typeof(Serializer)) &&
                    !(pi.PropertyType == typeof(TypeIdentifier)) &&
                    !(pi.PropertyType == typeof(StringBuilder)) && pi.GetGetMethod() != null)
                {
                    object value = pi.GetValue(obj, null); <--- here the Exception is thrown.
 
The Exception is a TargetParameterCountException with message "Parameter count mismatch." It looks somewhat similar to http://social.microsoft.com/Forums/en-US/netfxbcl/thread/2c6c0549-3240-4764-8ebe-8881ff8aa439
 
The fix is to skip this method for (I think) collections, as they will require an indexer to be passed to the GetValue... I made a quick workaround by skipping all Generic types:
 
    private static void evaluateAllStringProperties(object obj, serializingMode serializingMode)
    {
        if (obj != null)
        {
            foreach (PropertyInfo pi in obj.GetType().GetProperties())
            {
                if (!(pi.PropertyType == typeof(Serializer)) &&
                    !(pi.PropertyType == typeof(TypeIdentifier)) &&
                    !(pi.PropertyType.IsGenericType) &&                                 // THIS LINE WAS ADDED
                    !(pi.PropertyType == typeof(StringBuilder)) && pi.GetGetMethod() != null)
                {
                    object value = pi.GetValue(obj, null);
Would be great if you could fix this!
 
Gert-Jan Bark

comments