fasterflect
fasterflect copied to clipboard
Exception: Unable to cast DateTime to ValueTypeHolder
I created a MethodInvoker for DateTime.ToString(). When I call this as Invoker(DateTime.Now, null), I get this exception:
System.InvalidCastException: 'Unable to cast object of type 'System.DateTime' to type 'Fasterflect.Emitter.ValueTypeHolder'.'
Am I doing something wrong, or is this a bug in Fasterflect?
Method WrapIfValueType solves the problem. Code
DateTime.Now.WrapIfValueType().CallMethod("ToString")
works for me. Very strange, I cannot find any docs about the method and type ValueTypeHolder.