Bug 30171

Summary: BinaryReader.ReadChar() returns incorrect result on 8.10
Product: iOS Reporter: Cody Beyer (MSFT) <cody.beyer>
Component: GeneralAssignee: Marek Safar <masafa>
Severity: blocker CC: alex.koeplinger, danisha, jesper, miguel, mohitk, mono-bugs+monotouch, saper, suhasbjoshi
Priority: High    
Version: master   
Target Milestone: Untriaged   
Hardware: PC   
OS: Mac OS   
Tags: Is this bug a regression?: ---
Last known good build:
Attachments: TestCase

Description Cody Beyer (MSFT) 2015-05-17 14:08:10 UTC
Created attachment 11229 [details]

### Description

The following app attempts to read a stream, and do various conversions upon it. Using Xamarin.iOS 8.9, the results are correct. However, using 8.10 yields incorrect results.

                    char testchar2 = reader.ReadChar();

Does not return the correct value, causing further functions upon testchar2 to evaluate incorrectly. 

### Test Case


### Steps to Reproduce

1. Open attached test case
2. Run on Xamarin.iOS 8.10

### Expected Results

Output should look similar to: https://gist.github.com/CodyBeyer/2f04f5889e54ab0c7884

### Actual Results

Actual Output: https://gist.github.com/CodyBeyer/8a1f42f449c22bee5749

### Versions

=== Xamarin Studio ===

Version 5.9.2 (build 0)
Installation UUID: 061f61cf-c366-4da7-b3c9-31033d0fc883
	Mono 4.0.1 ((detached/6d5afc1)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 400010034

=== Apple Developer Tools ===

Xcode 6.3.1 (7703)
Build 6D1002

=== Xamarin.iOS ===

Version: (Business Edition)
Hash: b39367d
Branch: master
Build date: 2015-05-14 08:50:11-0400

=== Xamarin.Android ===

Version: (Business Edition)
Android SDK: /Users/beyerc/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)
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)

=== Xamarin Android Player ===

Version: Unknown version
Location: /Applications/Xamarin Android Player.app

=== Xamarin.Mac ===

Version: (Business Edition)

=== Build Information ===

Release ID: 509020000
Git revision: f97f3598952edca4678fc9fdafffecb68ed24399
Build date: 2015-05-08 11:55:56-04
Xamarin addins: ab18ddff45f507ed74f36c2b65df9aee22e28a56

=== Operating System ===

Mac OS X 10.10.3
Darwin Codys-MacBook-Pro.local 14.3.0 Darwin Kernel Version 14.3.0
    Mon Mar 23 11:59:05 PDT 2015
    root:xnu-2782.20.48~5/RELEASE_X86_64 x86_64
Comment 1 Miguel de Icaza [MSFT] 2015-05-18 12:39:02 UTC
This is a regression on IO.
Comment 3 Miguel de Icaza [MSFT] 2015-05-18 15:43:17 UTC
Marek, since this is a regression, it seems that we did a change in Mono in the 4.0 series that regressed.

Since it is unlikely that we would bring all this new code from master to Mono 4.0 as a service release, we should identify the source of the regression.
Comment 4 Marek Safar 2015-05-18 15:51:11 UTC
It's not kind of partial regression. We have reference sources Encoding which fixes/changes Encoding handling. BinaryReader was not updated and it's buggy to work with "correct" Encoding classes.

However, relevant changes are quite large. It all start at https://github.com/mono/referencesource/blob/mono/mscorlib/system/io/binaryreader.cs#L440

compare to https://github.com/mono/mono/blob/mono-4.0.0-branch/mcs/class/corlib/System.IO/BinaryReader.cs#L257

I can cook dirty change but that will fix only this particular issue (and we don't have great code coverage for it)
Comment 5 Marek Safar 2015-05-18 16:46:06 UTC
Closing as it works in master and SR fixes are not handled via bugzilla
Comment 6 Jesper 2015-05-19 16:09:57 UTC
I was the one reporting this bug. Because it meant that our 2 year old App suddenly could no longer load font metadata files because it uses BinaryReader for that. This is part of the Exen framework (a fork of MonoGame). This means it is pretty serious for us. Our app is actually broken because of lack of backward compatibility. I have temporarily solved it by rewriting Exen to use a JsonSerializer - but this means that all font metadata files are twice as big and loads slower.  I am not actually able to see from your comments whether this problem has been fixed in the next update to Xamarin. The bug has potentially broken all apps using fonts in Exen and probably MonoGame too (I do not know if MonoGame loads fonts the same way as Exen, seems probable since Exen is a fork of MonoGame)
Comment 7 Miguel de Icaza [MSFT] 2015-05-19 18:08:35 UTC
Thanks for sharing this information, it clearly has a more serious impact than I had anticipated.   We are restarting our QA process to bring this fix in.
Comment 8 Mohit Kheterpal 2015-05-20 07:03:24 UTC
I have checked this issue and able to reproduce it with monotouch- and observed that this issue is working fine with monotouch- as shown in screencast : http://www.screencast.com/t/58iq1oeMB

Hence closing this issue.
Comment 9 Alexander Köplinger 2015-05-21 11:50:34 UTC
This also affected DNX/Roslyn when running on Mono 4.0 and I can confirm that https://github.com/mono/mono/commit/ed1d3ec5260b613849b9af27c9dbcb6566c1637c fixes it, looking forward to seeing this in a SR :)
Comment 10 Danish Akhtar 2015-05-27 01:42:11 UTC
Today, I have checked this issue with X.iOS, now this issue is not exists. We are getting application output similar to mentioned in Expected result in bug description.

screencast for the same: http://www.screencast.com/t/ZJDfqV1oyy

Environment info:=== Xamarin Studio ===

Version 5.9.2 (build 2)
Installation UUID: 46d4d4b6-9307-4ad8-8136-09022b256dbf
	Mono 4.0.1 ((detached/ed1d3ec)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 400010044

=== Xamarin.Android ===

Version: (Enterprise Edition)
Android SDK: /Users/360_macmini/Desktop/android-sdk-macosx
	Supported Android versions:
		2.3    (API level 10)
		4.0.3  (API level 15)
		4.1    (API level 16)
		4.2    (API level 17)
		4.3    (API level 18)
		4.4    (API level 19)
		4.4.87 (API level 20)
		5.0    (API level 21)
Java SDK: /usr
java version "1.6.0_65"
Java(TM) SE Runtime Environment (build 1.6.0_65-b14-462-11M4609)
Java HotSpot(TM) 64-Bit Server VM (build 20.65-b04-462, mixed mode)

=== Xamarin Android Player ===

Not Installed

=== Apple Developer Tools ===

Xcode 6.2 (6776)
Build 6C131e

=== Xamarin.iOS ===

Version: (Enterprise Edition)
Hash: e6ebd18
Branch: master
Build date: 2015-05-21 21:55:09-0400

=== Xamarin.Mac ===

Version: (Enterprise Edition)

=== Build Information ===

Release ID: 509020002
Git revision: 43735a4b905b571f69cf9428a3ea7b52aef55476
Build date: 2015-05-18 09:38:12-04
Xamarin addins: ab18ddff45f507ed74f36c2b65df9aee22e28a56

=== Operating System ===

Mac OS X 10.9.5
Darwin 360-MACMINIs-Mac-mini.local 13.4.0 Darwin Kernel Version 13.4.0
    Sun Aug 17 19:50:11 PDT 2014
    root:xnu-2422.115.4~1/RELEASE_X86_64 x86_64
Comment 11 Marcin Cieślak 2015-06-04 18:11:00 UTC
Suspected duplicate: bug 29499
Comment 12 Alexander Köplinger [MSFT] 2016-03-01 12:48:03 UTC
*** Bug 29499 has been marked as a duplicate of this bug. ***