We make use of a custom value type that implements IConvertible
to be able to cast it as Double dynamically.
We have prototypes that return Object
and are susceptible to returning an instance of this type, on which we call CDbl.
In .net Framework, this works fine.
In .net5 this works fine.
In a netstandard library, this throws an InvalidCastException
. Looking at the code, it seems the compiler embeds some parts of code in a local Microsoft.VisualBasic.CompilerServices namespace, in our case it embeds a Conversions class that provides a ToDouble method. However, the code embeded in this case is not the same as the code in the visual basic library. It makes no provisions for IConvertible and just fails.
I have logged an issue on the roslyn repo, but it has stayed without answers so far. Has anyone noticed this and maybe found a workaround? In our case, switching all libraries to double targeting .net4.8 and net50 is not really an easy task, sdue to the architecture of our system, so I would rather not do it...