Skip to content

Console.Write prints a new line on iOS #36440

@rolfbjarne

Description

@rolfbjarne

Example:

Console.Write ("A");
Console.Write ("B");
Console.WriteLine ("C");

Output with .NET 5:

2020-05-14 12:50:56.386845+0200 MySingleView[89908:5086139] A
2020-05-14 12:50:56.386961+0200 MySingleView[89908:5086139] B
2020-05-14 12:50:56.387585+0200 MySingleView[89908:5086139] C

Output with current Xamarin.iOS:

2020-05-14 12:53:03.497594+0200 testapp[93230:5096504] ABC

The problem seems to be that mono's implementation stores text until a newline is written:

https://github.com/mono/mono/blob/f24a85069b3541ef45c8bbbd800ec7d88ad22e07/mcs/class/corlib/System/Console.iOS.cs#L81-L83

while dotnet's implementation writes out the text every time:

public override unsafe void Write(byte[] buffer, int offset, int count)
{
ValidateWrite(buffer, offset, count);
fixed (byte* ptr = buffer)
{
Interop.Sys.Log(ptr + offset, count);
}
}

and NSLog will append a newline if the text doesn't have one.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions