faunadb-csharp icon indicating copy to clipboard operation
faunadb-csharp copied to clipboard

[Bug] StringV is not castable to classes implementing ScalarValue<string>

Open Texnomic opened this issue 4 years ago • 0 comments

StringV is sealed class, so the only way to create a derived class is to inherit from ScalarValue<string>. The internal Decoder works one way only: ScalarValue<string> Derived Class to StringV but not the other way around.

Digging deeper into internal decoder implementation, the root cause is the usage of

typeof(StringV).IsAssignableFrom(typeof(DerivedClass))
typeof(DerivedClass).IsAssignableFrom(typeof(StringV))

which in both ways evaluates to false and throws Invalid Cast Exception.

This can be fixed in one of two ways:

  1. Making StringV not sealed
  2. Replacing IsAssignableFrom check with string or ScalarValue<string> check.

Texnomic avatar Jan 19 '22 22:01 Texnomic