This is Xamarin's bug tracking system. For product support, please use the support links listed in your Xamarin Account.
Bug 45046 - Console.WriteLine() crashes the app
Summary: Console.WriteLine() crashes the app
Alias: None
Product: iOS
Classification: Xamarin
Component: Xamarin.iOS.dll (show other bugs)
Version: XI 10.0 (iOS10)
Hardware: PC Mac OS
: Normal normal
Target Milestone: 10.2.2 (C8SR2)
Assignee: Rolf Bjarne Kvinge
: 45047 45048 (view as bug list)
Depends on:
Reported: 2016-10-05 12:01 UTC by Alexey Bogdanov
Modified: 2016-11-30 20:27 UTC (History)
6 users (show)

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

Crash log (79.89 KB, text/plain)
2016-11-16 15:04 UTC,

Description Alexey Bogdanov 2016-10-05 12:01:05 UTC
Calling Console.WriteLine() with some parameters crashes the app or gives strange output.

For examples:

In the empty (single view app) application gives this output:
"7            UTF8Stringrc23A2"

In our existing app it gives:
"7           autoreleaserc23A2"

In some cases similar input strings crash the app with this call stack:

critical: Stacktrace:
critical:   at <unknown> <0xffffffff>
critical:   at (wrapper managed-to-native) System.Console/NSLogWriter.xamarin_log (string) <IL 0x00011, 0x0010f>
critical:   at System.Console/NSLogWriter.Flush () [0x0000c] in /Users/builder/data/lanes/3818/ad1cd42d/source/xamarin-macios/_ios-build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/mcs/class/corlib/System/Console.iOS.cs:51
critical:   at System.Console/NSLogWriter.Write (char[],int,int) [0x0002f] in /Users/builder/data/lanes/3818/ad1cd42d/source/xamarin-macios/_ios-build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/mcs/class/corlib/System/Console.iOS.cs:89
critical:   at System.IO.TextWriter.WriteLine (string) [0x00083] in /Users/builder/data/lanes/3818/ad1cd42d/source/xamarin-macios/
critical:   at System.Console.WriteLine (string) [0x00000] in /Users/builder/data/lanes/3818/ad1cd42d/source/xamarin-macios/_ios-build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/mcs/class/corlib/System/Console.cs:429

It's critical bug, cause it can crash the app under some random circumstances.

Comment 1 Timothy Risi 2016-10-05 16:27:30 UTC
*** Bug 45047 has been marked as a duplicate of this bug. ***
Comment 2 Timothy Risi 2016-10-05 16:27:56 UTC
*** Bug 45048 has been marked as a duplicate of this bug. ***
Comment 3 Timothy Risi 2016-10-05 18:03:23 UTC
I'm seeing the same result as your first example (in an empty single view app), and get a different result if I try the same statement on XI 9 instead of 10.  Do you have an example of one that causes the app to crash?  And you could you provide your environment info?

The easiest way to get exact version information is to use the "Xamarin Studio" menu, "About Xamarin Studio" item, "Show Details" button and copy/paste the version informations (you can use the "Copy Information" button).
Comment 4 Alexey Bogdanov 2016-10-05 18:12:46 UTC
Unfortunately, the example that crashes is our production app and I cannot share the code.

Looks like some unmanaged memory is touched here. And sometimes it can be protected one.

I guess if the described strange output will be fixed, the crash will be fixed too.

=== Xamarin Studio Community ===

Version 6.1.1 (build 15)
Installation UUID: 99d6655c-999f-4283-81e7-dc9007ade8e2
	Mono 4.6.1 (mono-4.6.0-branch-c8sr0/ef43c15) (64-bit)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 406010005

=== NuGet ===


=== Xamarin.Profiler ===

Not Installed

=== Apple Developer Tools ===

Xcode 8.0 (11246)
Build 8A218a

=== Xamarin.Mac ===

Version: (Xamarin Studio Community)

=== Xamarin.Android ===

Version: (Xamarin Studio Community)
Android SDK: /Users/alexey/Library/Developer/Xamarin/android-sdk-macosx
	Supported Android versions:
		2.3   (API level 10)
		4.0.3 (API level 15)
		4.4   (API level 19)
		5.0   (API level 21)
		5.1   (API level 22)
		6.0   (API level 23)

SDK Tools Version: 25.1.3
SDK Platform Tools Version: 23.1
SDK Build Tools Version: 23.0.1

Java SDK: /usr
java version "1.7.0_71"
Java(TM) SE Runtime Environment (build 1.7.0_71-b14)
Java HotSpot(TM) 64-Bit Server VM (build 24.71-b01, mixed mode)

Android Designer EPL code available here:

=== Xamarin Android Player ===

Not Installed

=== Xamarin.iOS ===

Version: (Xamarin Studio Community)
Hash: ad1cd42
Branch: cycle8-sr0-xi
Build date: 2016-10-03 15:18:44-0400

=== Build Information ===

Release ID: 601010015
Git revision: fa52f02641726146e2589ed86ec4097fbe101888
Build date: 2016-09-22 08:03:02-04
Xamarin addins: 75d65712af93d54dc39ae4c42b21dfa574859fd6
Build lane: monodevelop-lion-cycle8-sr0

=== Operating System ===

Mac OS X 10.12.0
Darwin Alexeys-MacBook.local 16.0.0 Darwin Kernel Version 16.0.0
    Mon Aug 29 17:56:20 PDT 2016
    root:xnu-3789.1.32~3/RELEASE_X86_64 x86_64
Comment 5 Sebastien Pouliot 2016-10-05 20:03:57 UTC
@Rolf I wonder if this started with cfb84f6e

That makes xamarin_log create a unicode -> NSString -> UTF8String -> NSString (again) -> NSLog and I think that (beside the added complexity)the string data gets wrt formats.
Comment 7 Shruti 2016-10-13 12:26:46 UTC
Reproduce Status:

I have checked this issue and able to reproduce the issue as mentioned in comment0 and comment3 and application doesn't crash.

=== Xamarin.iOS ===
Version: (Xamarin Enterprise)
Hash: ad1cd42
Branch: cycle8-sr0-xi
Build date: 2016-10-03 15:18:44-0400

Supplement Info:

Environment Info and IDE Logs:

Verification Status

I have checked this issue with the master build mentioned in comment6 and observe that the issue is fixed. Calling Console.WriteLine() with some parameters doesn't crashes the app and gives expected output.

For examples:

Expected Output: %7B%22src%22%3A%22

=== Xamarin.iOS ===
Version: (Xamarin Enterprise)
Hash: d3ae54a
Branch: master
Build date: 2016-10-06 08:52:40-0400

Supplement Info:

Environment Info and IDE Log:

Hence, marking this issue as verified fixed.

Comment 8 2016-11-16 15:01:48 UTC
Issue still occurring in Xamarin.iOS with an iPad 2 running 9.3.5.

Executing this will produce the crash: 


The crash produces this stack trace:

2016-11-16 10:50:49.513 ItavioiOS[1758:315068] critical: Stacktrace:

2016-11-16 10:50:49.513 ItavioiOS[1758:315068] critical:   at <unknown> <0xffffffff>
2016-11-16 10:50:49.517 ItavioiOS[1758:315068] critical:   at (wrapper managed-to-native) System.Console/NSLogWriter.xamarin_log (string) <0x00053>
2016-11-16 10:50:49.528 ItavioiOS[1758:315068] critical:   at System.Console/NSLogWriter.Flush () [0x0000c] in /Users/builder/data/lanes/3969/44931ae8/source/xamarin-macios/_ios-build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/mcs/class/corlib/System/Console.iOS.cs:51
2016-11-16 10:50:49.532 ItavioiOS[1758:315068] critical:   at System.Console/NSLogWriter.Write (char[],int,int) [0x0002f] in /Users/builder/data/lanes/3969/44931ae8/source/xamarin-macios/_ios-build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/mcs/class/corlib/System/Console.iOS.cs:89
2016-11-16 10:50:49.539 ItavioiOS[1758:315068] critical:   at System.IO.TextWriter.WriteLine (string) [0x00083] in /Users/builder/data/lanes/3969/44931ae8/source/xamarin-macios/_ios-build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/mcs/class/referencesource/mscorlib/system/io/textwriter.cs:490
2016-11-16 10:50:49.540 ItavioiOS[1758:315068] critical:   at System.Console.WriteLine (string) [0x00000] in /Users/builder/data/lanes/3969/44931ae8/source/xamarin-macios/_ios-build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/mcs/class/corlib/System/Console.cs:429
2016-11-16 10:50:49.544 ItavioiOS[1758:315068] critical:   at Itavio.iOS.SurveyController.ViewDidLoad () [0x00021] in /Users/aaronmacdonald/Repositories/parent-app/Itavio/Itavio.iOS/SurveyController.cs:35
2016-11-16 10:50:49.544 ItavioiOS[1758:315068] critical:   at (wrapper runtime-invoke) object.runtime_invoke_dynamic (intptr,intptr,intptr,intptr) <0x000ff>
2016-11-16 10:50:49.545 ItavioiOS[1758:315068] critical:   at <unknown> <0xffffffff>
2016-11-16 10:50:49.553 ItavioiOS[1758:315068] critical:   at (wrapper managed-to-native) UIKit.UIApplication.UIApplicationMain (int,string[],intptr,intptr) <0x00063>
2016-11-16 10:50:49.562 ItavioiOS[1758:315068] critical:   at UIKit.UIApplication.Main (string[],intptr,intptr) [0x00005] in /Users/builder/data/lanes/3969/44931ae8/source/xamarin-macios/src/UIKit/UIApplication.cs:79
2016-11-16 10:50:49.566 ItavioiOS[1758:315068] critical:   at UIKit.UIApplication.Main (string[],string,string) [0x00038] in /Users/builder/data/lanes/3969/44931ae8/source/xamarin-macios/src/UIKit/UIApplication.cs:63
2016-11-16 10:50:49.567 ItavioiOS[1758:315068] critical:   at App4.Application.Main (string[]) [0x00008] in /Users/aaronmacdonald/Repositories/parent-app/Itavio/Itavio.iOS/Main.cs:14
2016-11-16 10:50:49.568 ItavioiOS[1758:315068] critical:   at (wrapper runtime-invoke) object.runtime_invoke_dynamic (intptr,intptr,intptr,intptr) <0x000ff>

Crash log attached.
Comment 9 2016-11-16 15:04:11 UTC
Created attachment 18483 [details]
Crash log

Crash observed in Xamarin iOS Version:
Comment 10 Rolf Bjarne Kvinge 2016-11-17 06:51:37 UTC
@Aaron, due to Apple releasing new iOS versions quickly, our version numbers end up a bit skewed. In particular we jumped from Xamarin.iOS 10.0 to Xamarin.iOS 10.2 when we added iOS 10.1 support to Xamarin.iOS 10.0 (and we _only_ added iOS 10.1 support, not anything else).

This means that Xamarin.iOS is technically an earlier version of Xamarin.iOS than (that was tested in comment #7).

The fix will be in Xamarin.iOS 10.4 (which is currently in the Alpha channel, and which may end up with yet a different version number if iOS 10.2 becomes to stable soon).

Note You need to log in before you can comment on or make changes to this bug.