fauna / faunadb-csharp

C# driver for FaunaDB v4

Home Page:https://fauna.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

Texnomic opened this issue · 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.