RickStrahl / Expando

Extensible dynamic types for .NET
108 stars 30 forks source link

I want to add properties of base class to serialization, but I'm getting weird error "Parameter count mismatch." #9

Closed glikoz closed 8 years ago

glikoz commented 8 years ago
public class A : Expando
{
   public string Prop1 { get; set; }
}

public class B : A 
{
   public string Prop2 { get; set; }
}

I want to serialize B, but only own properties are serialized, because of this line :

_InstancePropertyInfo = Instance.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly); so I replaced it with this:

_InstancePropertyInfo = Instance.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public) ; Now, I'm getting weird error during serialization:

"Parameter count mismatch."

Callstack says:

at System.Reflection.RuntimeMethodInfo.InvokeArgumentsCheck(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at System.Reflection.RuntimePropertyInfo.GetValue(Object obj, Object[] index)
   at Expando.<GetProperties>d__19.MoveNext() in ......
   at Expando.<GetDynamicMemberNames>d__9.MoveNext() in .....
   at JsonSerializerInternalWriter.SerializeDynamic(JsonWriter writer, IDynamicMetaObjectProvider value, JsonDynamicContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty)
glikoz commented 8 years ago

It seems, source of the problem is the "Item" Property, I eliminated it.And problem has gone.