Bug 6977 - Console.WriteLine produce garbled output for non-ascii characters
Summary: Console.WriteLine produce garbled output for non-ascii characters
Alias: None
Product: iOS
Classification: Xamarin
Component: General ()
Version: 5.5.x
Hardware: PC Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
Depends on:
Reported: 2012-09-07 05:49 UTC by Rolf Bjarne Kvinge [MSFT]
Modified: 2012-09-10 20:37 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 Developer Community or GitHub 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 Rolf Bjarne Kvinge [MSFT] 2012-09-07 05:49:52 UTC
Console.WriteLine ("abcñáéíó");



for both sim and device.
Comment 1 Sebastien Pouliot 2012-09-10 19:30:34 UTC
We need to switch to NSString if we don't want to be limited to MacRoman encoding. It's simple but a bit heavier. OTOH you should not be logging (too much) in released (non-debug) applications.

diff --git a/src/Foundation/NSLogWriter.cs b/src/Foundation/NSLogWriter.cs
index 6ced638..c72c2c8 100644
--- a/src/Foundation/NSLogWriter.cs
+++ b/src/Foundation/NSLogWriter.cs
@@ -19,9 +19,9 @@ namespace MonoTouch.Foundation {
        class NSLogWriter : TextWriter {
                [DllImport (MonoTouch.Constants.FoundationLibrary)]
-               extern static void NSLog (IntPtr format, string s);
+               extern static void NSLog (IntPtr format, IntPtr s);
-               static NSString format = new NSString ("%s");
+               static NSString format = new NSString ("%@");
                StringBuilder sb;
@@ -37,7 +37,8 @@ namespace MonoTouch.Foundation {
                public override void Flush ()
                        try {
-                               NSLog (format.Handle, sb.ToString ());
+                               using (var ns = new NSString (sb.ToString ()))
+                                       NSLog (format.Handle, ns.Handle);
                                sb.Length = 0;
                        catch (Exception) {
Comment 2 Miguel de Icaza [MSFT] 2012-09-10 20:27:23 UTC
Agreed, lets apply this to 5.4 + master
Comment 3 Sebastien Pouliot 2012-09-10 20:37:32 UTC
master: 3ba328c44b0cbf29acd173d644f49583d57ed8d1
monotouch-5.4-series: 60e6f6424534ad2bf38aefeb5f1ebc50b84d604e