[Mono-dev] trouble with mono's handling of "unsafe struct pointers" vs MS.NET...

Rodrigo Kumpera kumpera at gmail.com
Fri Aug 17 20:40:39 UTC 2012


On Fri, Aug 17, 2012 at 4:16 PM, David Jeske <davidj at gmail.com> wrote:

> I have a C# wrapper for a native DLL which exists on both windows and
> UNIX. However, it doesn't work on Mono because of a behavior difference
> between Mono and MS.NET.
>
>
> My questions:
>
> (1) Why is Mono complaining about this? AFAIK, in the CLR, an unsafe
> struct pointer is not a marshalled structure, it's a value type.
>

The marshal code plays it safe, so when we don't know how to marshal a
given parameter we proactively fail.


(2) Why would it suggest using ByRef? ByRef is for managed pointers to
> managed data. This is a value-type pointer value.  AFAIK, ByRef is not
> capable of doing anything here, because the pointer is just a "typed"
> IntPtr value type.
>

This is because byrefs are GC visible while pointers are not, or something.
Well, honestly, no idea.

(3) I think this used to work in older versions of mono. Is there some
> particular reason the behavior has changed? Do folks agree this is a
> problem?
>

The code that made this ilegal is from 2005 so, yeah, in some very very old
version of mono it did work. Anyway, we've reverted to allow
any pointer to structs on the upcoming 2.12 release. The change is
f8f2da07c9b0a609f07aa342b49e4dcb7f6bf6b4.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ximian.com/pipermail/mono-devel-list/attachments/20120817/88363342/attachment.html>


More information about the Mono-devel-list mailing list