Bug 11848 - Visual Studio output window displays Console.WriteLine() twice
Summary: Visual Studio output window displays Console.WriteLine() twice
Status: RESOLVED NOT_REPRODUCIBLE
Alias: None
Product: Android
Classification: Xamarin
Component: Debugger ()
Version: 4.6.x
Hardware: PC Windows
: Normal normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2013-04-18 11:52 UTC by Arthur
Modified: 2018-05-12 10:28 UTC (History)
25 users (show)

Tags:
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:
Status:
RESOLVED NOT_REPRODUCIBLE

Description Arthur 2013-04-18 11:52:00 UTC
Console.WriteLine(..) results in a double entry in the Visual Studio Output window.

Example:

04-18 23:30:50.802 I/mono-stdout( 6871): Banana Angle:30 Left:37 Top:669 Right:345 Bottom:743
Banana Angle:30 Left:37 Top:669 Right:345 Bottom:743
Cherry Angle:60 Left:-102 Top:809 Right:205 Bottom:883
04-18 23:30:50.802 I/mono-stdout( 6871): Cherry Angle:60 Left:-102 Top:809 Right:205 Bottom:883
Comment 1 RichardH 2014-04-29 23:46:49 UTC
I'm having the same issue in Xamarin Studio.  Every Console.WriteLine() is being displayed twice in the output.

This only appears to affect my Xamarin.Android projects and not Xamarin.iOS.
Comment 2 frederic torres 2014-09-08 22:37:07 UTC
I am seeing this issue also with Xamarin.iOS
Comment 3 sothy.chan 2014-09-16 17:07:41 UTC
I'm having the same issue on Xamarin.Android.  I haven't noticed this issue in Xamarin.iOS.
Comment 4 William 2014-11-11 13:30:18 UTC
In a new Android app on my machine, Debug.WriteLine gets written twice (blue and black fonts) though Console.WriteLine is only written once (black font).

Here is the click code in the sample app:
button.Click += delegate
            {
                button.Text = string.Format("{0} clicks!", count++);
                Console.WriteLine("Console.WriteLine");
                System.Diagnostics.Debug.WriteLine("Debug.WriteLine");
            };

And the following is from the application output:
Console.WriteLine
Debug.WriteLine
Debug.WriteLine
Comment 5 Alexey Kinev 2014-12-04 09:40:20 UTC
I have same issue with Debug.WriteLine in Xamarin.Forms / iOS project, it prints all messages twice, fist with black font, second with blue one.
Comment 6 Eric Weinschenk 2015-03-12 22:47:48 UTC
Bump!
Comment 7 Mike 2015-04-21 22:02:30 UTC
I'm seeing this in Visual Studio 2013 Pro with Xamarin Business fully updated.  I'm surprised this one isn't fixed yet - or are we all just doing something silly here?

Thanks!
Mike
Comment 8 Olaf Bartelt 2015-05-11 06:06:02 UTC
I have that issue too, but only with Xamarin for Android.
Comment 9 Nicholas Ventimiglia 2015-05-28 16:49:48 UTC
Me too.

Xamarin Studio Duplicate Console Application Output 
Log, Double, Duplicate, Repeat, Black, Blue
Comment 10 vinnievivace 2015-06-21 19:56:19 UTC
"me too"

Xamarin Studio, IOS project with PCL:

System.Diagnostics.Debug.WriteLine("seeing double")

outputs twice, black then blue.
Comment 11 renan jegouzo 2015-08-07 11:02:47 UTC
me too with iOS projects..
Comment 12 Rich Seviora 2015-10-17 13:06:39 UTC
I have the same problem. Debug.WriteLine generates multiple lines.

Here's a sample from Visual Studio 2015 from one line being generated.

2015-10-17 09:54:11.356 SweatRecordMobileiOS[36176:16807983] [TRACE: SweatRecordMobile.Model.Workout.PersistNew] Creating Record ID 0
[0:] [TRACE: SweatRecordMobile.Model.Workout.PersistNew] Creating Record ID 0
[0:] 


System Info:

Microsoft Visual Studio Community 2015
Version 14.0.23107.0 D14REL
Microsoft .NET Framework
Version 4.6.00079

Installed Version: Community

Visual Basic 2015   00322-20000-00000-AA189
Microsoft Visual Basic 2015

Visual C# 2015   00322-20000-00000-AA189
Microsoft Visual C# 2015

Visual C++ 2015   00322-20000-00000-AA189
Microsoft Visual C++ 2015

Windows Phone SDK 8.0 - ENU   00322-20000-00000-AA189
Windows Phone SDK 8.0 - ENU

Application Insights Tools for Visual Studio Package   1.0
Application Insights Tools for Visual Studio

ASP.NET and Web Tools   14.0.20626.0
ASP.NET and Web Tools

ASP.NET Web Frameworks and Tools 2013   5.2.30624.0
For additional information, visit http://www.asp.net/

Common Azure Tools   1.5
Provides common services for use by Azure Mobile Services and Microsoft Azure Tools.

GenerateUnitTest   1.0
Generates unit test code for methods in classes under test.

JetBrains ReSharper Ultimate 2015.2   Build 103.0.20150818.200216
JetBrains ReSharper Ultimate package for Microsoft Visual Studio. For more information about ReSharper Ultimate, visit http://www.jetbrains.com/resharper. Copyright © 2015 JetBrains, Inc.

Microsoft Azure Mobile Services Tools   1.4
Microsoft Azure Mobile Services Tools

NuGet Package Manager   3.2.0
NuGet Package Manager in Visual Studio. For more information about NuGet, visit http://docs.nuget.org/.

PreEmptive Analytics Visualizer   1.2
Microsoft Visual Studio extension to visualize aggregated summaries from the PreEmptive Analytics product.

SQL Server Data Tools   14.0.50616.0
Microsoft SQL Server Data Tools

Visual Studio Tools for Universal Windows Apps   14.0.23309.00 d14oob
The Visual Studio Tools for Universal Windows apps allow you to build a single universal app experience that can reach every device running Windows 10: phone, tablet, PC, and more. It includes the Microsoft Windows 10 Software Development Kit.

Xamarin   3.11.1443.0 (39031d3)
Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android.

Xamarin.Android   5.1.6.7 (58099c5358da3488b0e7fb0bb4af47aca7cc61d6)
Visual Studio plugin to enable development for Xamarin.Android.

Xamarin.Forms Intellisense   1.0
Provides intellisense for Xamarin.Forms in the XML editor.

Xamarin.iOS   9.0.1.0 (7eaf3bc2053ad0d4f720422bb3dc13504d61f7b5)
Visual Studio extension to enable development for Xamarin.iOS.

Xamarin.iOS Unified Migration   1.0
Automated migration for Xamarin iOS Classic projects to Unified

Xamarin.TestCloud.Integration   1.0
Early preview of Xamarin Test Cloud integration
Comment 13 renan jegouzo 2015-10-18 05:17:48 UTC
it's an important bug, it makes the console output unreadable..
Comment 14 rfreschi 2015-11-13 16:43:23 UTC
Same here with XS, iOS and Droid.
This bug was first reported in 2013 and still no resolution?
Comment 15 Rich Seviora 2015-11-14 00:30:22 UTC
Right? I mean, whatever this is it can't be *that* complicated...
Comment 16 renan jegouzo 2016-02-13 09:05:11 UTC
on iOS I found a trick 
I was using System.Diagnostics.Debug.Print(..)  that display twice
but System.Console.WriteLine(..) display only once

so just create
public class Debug
{
	[ Conditional("DEBUG") ]
	public static void Print (string s)
	{
		System.Console.WriteLine(s);
	}
}
and call this class, not Diagnostics one
Comment 17 thomas 2016-02-29 12:59:19 UTC
Still not solved and it caused about an hour work to find this out. Before I was sure, that part of my App get called twice.

Sorry, but it's a shame that nobody tales care about this!
Comment 18 Andrew Page 2016-05-30 14:41:52 UTC
This is very annoying when trying to debug something.  In Xamarin Studio I see one line that is date/time stamped followed by the debug output in black and another right behind that is just the debug message but in blue.  It clutters the output realestate terribly and makes any kind of formatting you apply nearly worthless.

I have however found a workaround.  I'm loathe to post it, since it will just give the owner of this bug an excuse to do 'nothing' but since they seem to be in 'ignore the indie coders and they'll go away' mode anyway...

I've tried this on the IOS simulator and it removes the secondary 'blue' line mentioned above.  This is crude and off-the-cuff and could stand some tuning but it demonstrates the basic nuts&bolts.   We take out the existing listener and replace it with a new one that just routes the output to the console.    That this eliminates the extraneous output seems to point that the 'bug'(if you consider the duplicate output a bug) is in the original registered 'tracelistener'.   YMMV

-------------------------------------

using System.Diagnostics ;

public class listener  : TraceListener {
    public override void Write(string message) // override abstract method
    {
      Console.Write(message);
    }

    public override void WriteLine(string message) // override abstract method
    {
      Console.WriteLine(message);
    }
  }

[Register("AppDelegate")]
public partial class AppDelegate : global::Xamarin.Forms.Platform.iOS.FormsApplicationDelegate
{
  public override bool FinishedLaunching(UIApplication app, NSDictionary options)
  {
    Debug.Listeners.RemoveAt(0); // remove troublesome output duping listener

    Debug.Listeners.Add(new listener());
    global::Xamarin.Forms.Forms.Init();

    LoadApplication(new App());

    return base.FinishedLaunching(app, options);
  }
}

------------------------------------
Comment 19 Cody Beyer (MSFT) 2017-06-30 02:11:14 UTC
Thank you for taking the time to submit this report. After reviewing the description of this bug, we believe it no longer affects the current version of Xamarin.Android. If you are still experiencing the issue after updating your packages, please reopen this report with an attached reproduction.
Comment 20 Cody Beyer (MSFT) 2017-06-30 02:25:57 UTC
Unfortunately, we’re unable to reproduce this report. If this issue is still occurring for you, please reopen this issue and attach a reproduction to the bug by starting with a clean Xamarin.Android project adding just the code necessary to demonstrate the issue.
Comment 21 Sergey Yurkov 2018-05-11 05:05:35 UTC
I'm still getting this error.

Microsoft Visual Studio Community 2017 
Version 15.6.6
VisualStudio.15.Release/15.6.6+27428.2037

Xamarin   4.9.0.753 (f0f46392f)
Xamarin Designer   4.10.96 (a702a9ceb)
Xamarin.Android SDK   8.2.0.16 (HEAD/a78295902)
Comment 22 Olaf Bartelt 2018-05-11 09:52:05 UTC
Me too. Totally annoying and embarassing for Xamarin/MS... But there's a whole load of other bugs in it, so...
Comment 23 Sergey Yurkov 2018-05-12 10:28:58 UTC
Well, if anyone is looking for a fix for Xamarin.Android here is the dirty one:

TextWriter syncTextWriter = Console.Out;
FieldInfo fieldInfo = syncTextWriter
    .GetType()
    .GetField("_out", BindingFlags.Instance | BindingFlags.NonPublic);
TextWriter logcatTextWriter = (TextWriter)fieldInfo.GetValue(syncTextWriter);
fieldInfo = logcatTextWriter
    .GetType()
    .GetField("stdout", BindingFlags.Instance | BindingFlags.NonPublic);
TextWriter originalTextWriter = (TextWriter)fieldInfo.GetValue(logcatTextWriter);
Console.SetOut(originalTextWriter);
fieldInfo.SetValue(logcatTextWriter, null);

Here we dive into the guts of LogcatTextWriter and extract the original TextWriter. LogcatTextWriter produces the bug (in fact it's not a bug but a "feature" that was written like that all these years). Cons is that you will lose LogCat messages. So you should probably comment this hack before running your app on a remote device or in production.

Shame on you Xamarin for RESOLVED NOT_REPRODUCIBLE status. MS really should decimate somebody.