I have an issue where I copied a method from solution A to solution B, where it does not work properly anymore. It is weird because I explicitly looked for any dependencies, any frameworks that might be missing but couldn't find anything out.
So I have the following:
var ps = new PropertySet();
ps.SetProperty("id", 4711);
ps.SetProperty("guid", Guid.NewGuid());
var s = JsonConvert.SerializeObject(ps, formatting: Formatting.Indented);
var ps2 = JsonConvert.DeserializeObject<PropertySet>(s);
AssertEqualProperty<int>(ps["id"], ps2["id"]);
// ...............................
private static void AssertEqualProperty<T>(JToken expected, JToken current)
{
Assert.AreEqual(expected.ToObject<T>(), current.ToObject<T>());
}
On the last line, I get an error on ps["id"]
and ps2["id"]
stating:
Cannot apply indexing with [] to an expression of type PropertySet Cannot access internal "this" here
The class PropertySet
in solution A contains this line:
internal JToken this[string key] {get... set...}
Could this be the issue? Is there any workaround possible?