[Mono-list] passing MonoArray from c#

Robert Jordan robertj at gmx.net
Sat May 2 17:36:25 EDT 2009


fozzie wrote:
> mMonoClass->invoke() is just looking up the method name then calling
> mono_runtime_invoke(). Trace statements show that the Pack() method is
> receiving the parameters correctly and returns. It gets the correct return
> value for other c# methods, but they are returning scalars rather than
> arrays.

Arrays are objects in mono. If your method is able to return
MonoObjects* then it will work with arrays just fine.

I guess your mMonoClass->invoke() is simply not checking
whether an exception has occurred. It's the last argument
to mono_runtime_invoke.

> There is another wrinkle in this - the call is crossing domain boundaries on
> the c# side. There is an exception at runtime if the Link and Data
> structures are not declared serializable.

Switch the domains (mono_domain_set()) before calling the
method but ensure that all objects passed as arguments are
originating from the correct domain.

If you cannot ensure this, then you must go over the remoting
stack. This is transparent even in embedding scenarios.
Of course, the classes must be either serializable or MBRs,
but at least you won't lose your mind.

> I think there may be too many moving pieces in this solution. Do you know of
> an easier way to do this? Maybe i can pass a MonoArray** from the unmanaged
> code, receive it as an [out] parameter on the c# side, fill it with Link
> data, and return? I'm not sure how to do this, unfortunately. 

This won't save you the domain switch.

Robert



More information about the Mono-list mailing list