Bug 3871 - Embedded Mono not Marshaling DllImport methods which return strings correctly on Windows
Summary: Embedded Mono not Marshaling DllImport methods which return strings correctly...
Alias: None
Product: Runtime
Classification: Mono
Component: Interop ()
Version: unspecified
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Bugzilla
Depends on:
Reported: 2012-03-13 11:22 UTC by Eric Fontana
Modified: 2012-09-02 13:31 UTC (History)
4 users (show)

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

Zip file containing both C# assembly and C++ driving program. (18.43 KB, application/octet-stream)
2012-03-13 11:26 UTC, Eric Fontana

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 Eric Fontana 2012-03-13 11:22:29 UTC
On Windows, my application which uses Embedded Mono is not marshalling
string correctly as return values.

The strings come back as all Question marks (possibly unicode?)

However, the same technique using IntPtr works.

Attached is the project
Comment 1 Eric Fontana 2012-03-13 11:26:20 UTC
Created attachment 1508 [details]
Zip file containing both C# assembly and C++ driving program.
Comment 2 Eric Fontana 2012-03-13 11:48:25 UTC
I should have said this is on Windows using Mono-2.10.8
Comment 3 Eric Fontana 2012-03-13 12:55:48 UTC
One additional thing here, My machine is Win7 64-bit, and I built mono.lib
using the instructions found here:

Comment 4 Zoltan Varga 2012-03-13 23:18:15 UTC
try 	[return: MarshalAs(UnmanagedType.LPWStr)]
on the pinvoke declaration.
Comment 5 Eric Fontana 2012-03-14 05:38:46 UTC
Tried your suggestion, same garbage result, also tried UnmanagedType.LPStr, no 

Robert Jordan tried the code himself in a non-embedded fashion, it also shows 
the bug, his test code is here:


He confirmed the problem with Mono-2.10.8, but said the code did work with
a master based build, so hopefully it has already been fixed, I did some
diffs against marshal.c and there were some changes that seemed related.