Bug 5007 - ref string, ref StringBuilder does not work (char**)
Summary: ref string, ref StringBuilder does not work (char**)
Alias: None
Product: Runtime
Classification: Mono
Component: Interop ()
Version: unspecified
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Bugzilla
Depends on:
Reported: 2012-05-10 12:07 UTC by Joe
Modified: 2012-05-13 20:44 UTC (History)
3 users (show)

Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description Joe 2012-05-10 12:07:54 UTC
The following PInvokes do not work:
        [DllImport("MarshalTest.Unmanaged.dll", CallingConvention = CallingConvention.Cdecl)]
        public static extern void TestString(ref string s);//Does not crash, but the data isn't copied back from unmanaged.

        [DllImport("MarshalTest.Unmanaged.dll", CallingConvention = CallingConvention.Cdecl)]
        public static extern void TestString(ref StringBuilder s);//Crashes with * Assertion at marshal.c:6525, condition `(t->attrs & PARAM_ATTRIBUTE_OUT)' not met

Both work on MS.NET when preallocated.

https://bugzilla.xamarin.com/show_bug.cgi?id=487 may be related.
Comment 1 Zoltan Varga 2012-05-13 10:04:33 UTC
Fixed the first case, and change the second to an exception instead of an assert.
Comment 2 Joe 2012-05-13 10:28:17 UTC
Thanks Zoltan. Is the second case planned to stay as an exception?
Comment 3 Zoltan Varga 2012-05-13 11:01:45 UTC
Comment 4 Zoltan Varga 2012-05-13 20:44:02 UTC
Fixed in master/2.10.