PathBinder.AccessMember tries to find method ContainsKey via reflection for instances that implement generic IDictionary<,> interface. However, at the moment this throws a NullReferenceException if the instance implements ContainsKey method using explicit interface implementation.
Is there any reason to call GetMethod for the concrete instance type instead for the dictionary interface type? It seems that replacing
// Lines 287 - 290 in PathBinder.cs
if ((bool)instanceType.GetMethod("ContainsKey").Invoke(instance, new[] { key }))
{
return instanceType.GetMethod("get_Item").Invoke(instance, new[] { key });
}
with
if ((bool)iDictInstance.GetMethod("ContainsKey").Invoke(instance, new[] { key }))
{
return iDictInstance.GetMethod("get_Item").Invoke(instance, new[] { key });
}
would fix the issue.
Obviously this might break some code in some rare cases (e.g. a class which is derived from Dictionary and which provides a new (non-virtual) implementation for ContainsKey).
PathBinder.AccessMember tries to find method ContainsKey via reflection for instances that implement generic IDictionary<,> interface. However, at the moment this throws a NullReferenceException if the instance implements ContainsKey method using explicit interface implementation.
Is there any reason to call GetMethod for the concrete instance type instead for the dictionary interface type? It seems that replacing
with
would fix the issue.
Obviously this might break some code in some rare cases (e.g. a class which is derived from Dictionary and which provides a new (non-virtual) implementation for ContainsKey).