[Mono-dev] SWIG Corrupt Strings - Delegate/System.String inner working changed from mono-2.8 to mono-2.10?

Sen sen121 at yopmail.com
Fri Dec 2 14:28:12 EST 2011

I've been using SWIG for a while now, and never had any problems with Mono
2.6, but ever since I upgraded to Mono 2.10.6, all strings coming from C++
get completely corrupted. (using Windows/VC.NET here, with predistributed

Tried to isolate between which versions the string handling broke, and it
seems to be working fine with Mono 2.8, but breaks with 2.10(.0).

How SWIG returns its strings is by a callback, to generate a System.String
from a char*:

And then through a P/Invoke function where a string is returned:

Which is bound through the following C# class:

Already done some debugging by adding System.Console.WriteLine(cString) in
the "static string CreateString(string cString)" function. This yields a
corrupt string (expected Test 1, got something like T&e^s ). Replacing that
by a System.IntPtr and using Marshal.PtrToStringAnsi, does yield the
expected string in Mono 2.10, but then the ultimate string given back
through P/Invoke is still corrupt.

Also tried to remove the "jresult = SWIG_csharp_string_callback((const char
*)result);" part, and just return the char* string directly; this gives a
similar corrupt string.

I have no idea what change from Mono 2.8 to Mono 2.10 triggered this
behavior; I've tried looking for clues in the changelog but nothing mentions
a major change to either the string class or delegate handling, so I'm
totally lost on how to fix something like this..

Any clues?

Kind regards,
L Sikkes

View this message in context: http://mono.1490590.n4.nabble.com/SWIG-Corrupt-Strings-Delegate-System-String-inner-working-changed-from-mono-2-8-to-mono-2-10-tp4148689p4148689.html
Sent from the Mono - Dev mailing list archive at Nabble.com.

More information about the Mono-devel-list mailing list