[Mono-dev] ValueTypes and mono_runtime_invoke

Robert Jordan robertj at gmx.net
Thu May 29 20:12:31 EDT 2008


Sebastian Good wrote:
> I have wrapped a function which returns a DateTime and call it using
> mono_runtime_invoke. This is a static method, so I don't pass in NULL for
> the object and parameters, and get a MonoObject* back. My understanding is

"I don't pass in NULL the object and parameters" does not make sense
as you must pass NULL in this case.

> that this MonoObject* should be a boxed DateTime. When I attempt to use this
> DateTime (e.g. by calling ToString() on it) it appears to be a clean
> MonoObject, but it contains a value very close to the default value for
> DateTime, namely "1/1/0001 12:00:04 AM". This suggests it has been lost
> somewhere between the underlying function call and the result of
> mono_runtime_invoke. In cases of functions which return primitive
> ValueTypes, there is no problem, e.g. int marshaled_ret_val =
> *reinterpret_cast<int*>(mono_object_unbox(ret_val));
> 
> I am happy to carry around a boxed version of the ValueType (DateTime) as I
> have to box it to call functions on it anyway through the embedding API. Any
> ideas?

Returning boxed valuetypes is usually working as expected. Please
show some code (C++ and C#).

Robert



More information about the Mono-devel-list mailing list