The following C # calls Microsoft.CSharp.RuntimeBinder. RuntimeBinderException on line 2.
dynamic element = JsonConvert.DeserializeObject<dynamic>("{ Key: \"key1\" }");
bool match = "key1".Equals(element.Key, StringComparison.InvariantCulture);
Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: Member 'object.Equals (object, object)' cannot be accessed with reference to the instance; qualify it instead of type name
Link to the Json.NET 8.0.3 project
<package id="Newtonsoft.Json" version="8.0.3" targetFramework="net452" />
I can get around the exception by explicitly converting element.Keyto System.String.
bool match = "key1".Equals((string)element.Key, StringComparison.InvariantCulture);
When checking element.Key.GetType()returns Newtonsoft.Json.Linq.JValue.
Why doesn't the DLR seem to know which method to call and end the call to the static method object.Equals(object, object)?
Edit:
, , , dynamic, System.Object .
bool match = "key1".Equals((object)element.Key, StringComparison.InvariantCulture);