fasterflect icon indicating copy to clipboard operation
fasterflect copied to clipboard

Exception: Unable to cast DateTime to ValueTypeHolder

Open asthomas opened this issue 4 years ago • 1 comments

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?

asthomas avatar Jul 03 '21 15:07 asthomas

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.

Kladzey avatar Oct 11 '21 14:10 Kladzey