Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Regression: Newtonsoft.Json.JsonReaderException on Xamarin.Android v 10.0.0.40 #3626

Closed
brminnick opened this issue Sep 13, 2019 · 7 comments · Fixed by #3686
Closed

Regression: Newtonsoft.Json.JsonReaderException on Xamarin.Android v 10.0.0.40 #3626

brminnick opened this issue Sep 13, 2019 · 7 comments · Fixed by #3686
Assignees
Labels
Area: Linker Issues when linking assemblies. regression

Comments

@brminnick
Copy link

Reproduction sample: https://github.com/brminnick/JsonParseTextRepro/

Steps to Reproduce

  1. Install the VS for Mac Preview Build available on 13 September 0300 UTC (Environment information, below)
  2. Download/clone reproduction sample: https://github.com/brminnick/JsonParseTextRepro/
  3. In Visual Studio for Mac, open JsonParseTextRepro.sln
  4. Set the Build Configration to DEBUG
  5. Build/Deploy the JsonParseTextRepro.Android project to an Android Emulator or Physical Device
  6. Verify display shows the following Exception: Newtonsoft.Json.JsonReaderException

Expected Behavior

The JSON should parse successfully, no exception should be thrown, displaying Success on the screen.

Actual Behavior

Newtonsoft.Json.JsonReaderException is thrown.

Work Around

  1. Install the VS for Mac Stable Build available on 13 September 0300 UTC, VS for Mac v8.2.6 (build 28)
  2. Download/clone reproduction sample: https://github.com/brminnick/JsonParseTextRepro/
  3. In Visual Studio for Mac, open JsonParseTextRepro.sln
  4. Set the Build Configration to DEBUG
  5. Build/Deploy the JsonParseTextRepro.Android project to an Android Emulator or Physical Device
  6. Verify the display shows Success

Environment

=== Visual Studio Enterprise 2019 for Mac (Preview) ===

Version 8.3 Preview (8.3 build 1630)
Installation UUID: 6e5142b4-e8be-4d1c-b75e-4744b0d8c3de
GTK+ 2.24.23 (Raleigh theme)
Xamarin.Mac 5.16.1.24 (d16-3 / 08809f5b)

Package version: 604000190

=== Mono Framework MDK ===

Runtime:
Mono 6.4.0.190 (2019-06/6b4b99e571b) (64-bit)
Package version: 604000190

=== NuGet ===

Version: 5.3.0.6192

=== .NET Core ===

Runtime: /usr/local/share/dotnet/dotnet
Runtime Versions:
3.0.0-preview9-19423-09
3.0.0-preview6-27804-01
2.2.5
2.1.9
2.1.2
2.1.1
2.0.5
2.0.0
1.1.1
1.0.4
SDK: /usr/local/share/dotnet/sdk/3.0.100-preview9-014004/Sdks
SDK Versions:
3.0.100-preview9-014004
3.0.100-preview6-012264
2.2.107
2.1.505
2.1.302
2.1.301
2.1.4
2.0.0
1.0.1
MSBuild SDKs: /Library/Frameworks/Mono.framework/Versions/6.4.0/lib/mono/msbuild/Current/bin/Sdks

=== Xamarin.Profiler ===

Version: 1.6.11.16
Location: /Applications/Xamarin Profiler.app/Contents/MacOS/Xamarin Profiler

=== Updater ===

Version: 11

=== Xamarin.Android ===

Version: 10.0.0.40 (Visual Studio Enterprise)
Commit: xamarin-android/d16-3/080eaac
Android SDK: /Users/brandonm/Library/Developer/Xamarin/android-sdk-macosx
Supported Android versions:
None installed

SDK Tools Version: 26.1.1
SDK Platform Tools Version: 28.0.2
SDK Build Tools Version: 28.0.3

Build Information:
Mono: mono/mono@6434153d8b7
Java.Interop: xamarin/java.interop/d16-3@5836f58
LibZipSharp: grendello/LibZipSharp/d16-3@71f4a94
LibZip: nih-at/libzip@b95cf3f
ProGuard: xamarin/proguard@905836d
SQLite: xamarin/sqlite@8212a2d
Xamarin.Android Tools: xamarin/xamarin-android-tools/d16-3@cb41333

=== Microsoft Mobile OpenJDK ===

Java SDK: /Users/brandonm/Library/Developer/Xamarin/jdk/microsoft_dist_openjdk_1.8.0.25
1.8.0-25
Android Designer EPL code available here:
https://github.com/xamarin/AndroidDesigner.EPL

=== Android SDK Manager ===

Version: 1.4.0.64
Hash: f70cfd2
Branch: remotes/origin/d16-3
Build date: 2019-09-02 17:32:00 UTC

=== Android Device Manager ===

Version: 1.2.0.112
Hash: 791e68e
Branch: remotes/origin/d16-3
Build date: 2019-09-02 17:32:26 UTC

=== Xamarin Designer ===

Version: 16.3.0.178
Hash: 725c87d57
Branch: remotes/origin/d16-3
Build date: 2019-08-29 22:57:50 UTC

=== Apple Developer Tools ===

Xcode 11.0 (14935)
Build 11A419c

=== Xamarin.Mac ===

Version: 5.16.1.24 (Visual Studio Enterprise)
Hash: 08809f5b
Branch: d16-3
Build date: 2019-09-06 08:42:41-0400

=== Xamarin.iOS ===

Version: 12.16.1.24 (Visual Studio Enterprise)
Hash: 08809f5b
Branch: d16-3
Build date: 2019-09-06 08:42:42-0400

=== Xamarin Inspector ===

Version: 1.4.3
Hash: db27525
Branch: 1.4-release
Build date: Mon, 09 Jul 2018 21:20:18 GMT
Client compatibility: 1

=== Build Information ===

Release ID: 803001630
Git revision: 456143789d948850ef2518c7401bcd0637d88e99
Build date: 2019-09-11 21:24:24+00
Build branch: release-8.3-preview4
Xamarin extensions: 52c395755d16d1c7077d3568574a19af9a23b423

=== Operating System ===

Mac OS X 10.15.0
Darwin 19.0.0 Darwin Kernel Version 19.0.0
Sun Aug 18 23:37:31 PDT 2019
root:xnu-6153.0.166~17/RELEASE_X86_64 x86_64

@brendanzagaeski brendanzagaeski added Area: Linker Issues when linking assemblies. regression labels Sep 14, 2019
@brendanzagaeski brendanzagaeski added this to the d16-3 milestone Sep 14, 2019
@brendanzagaeski
Copy link
Contributor

Thanks for the report! This problem appears to be due to an incorrect change in behavior in the managed linker.

Candidate workaround:

Add a new linker.xml file to the project, set the Build Action to LinkDescription, and add the following lines to it to preserve the AndroidClientHandler type:

<linker>
  <assembly fullname="Mono.Android">
    <type fullname="Xamarin.Android.Net.AndroidClientHandler" preserve="all" />
  </assembly>
</linker>

This resolved the issue in my local environment, testing with the JsonParseTextRepro example project on an Android 7.0 Nougat (API level 25) x86_64, Google APIs emulator (system-images;android-25;google_apis;x86_64).

Additional notes for the team members who work on the managed linker:

  • The sample project has both $(BundleAssemblies) and $(AotAssemblies) enabled for the Debug configuration. I found that neither one was required to reproduce this particular issue, so I removed the following lines from the project when I was testing to simplify the scenario:

    <BundleAssemblies>true</BundleAssemblies>
    <AotAssemblies>true</AotAssemblies>
  • I compared the output of ildasm -text -noil -classlist for Mono.Android.dll in the APK built using Xamarin.Android 9.4.1.1 in Visual Studio 2019 version 16.2 versus the APK built using Xamarin.Android 10.0.0.40 in Visual Studio 2019 version 16.4 Int Preview. Several types were missing from Mono.Android.dll in the APK built using Xamarin.Android 10.0.0.40. Adding the linker.xml custom linker configuration file to preserve Xamarin.Android.Net.AndroidClientHandler restored the original list of types. Here are the outputs I got, passed through sort:

@brendanzagaeski
Copy link
Contributor

Stack trace of the Newtonsoft.Json.JsonReaderException exception message:

Newtonsoft.Json.JsonReaderException: Unexpected character encountered while parsing value: �. Path '', line 0, position 0.Newtonsoft.Json.JsonReaderException: Unexpected character encountered while parsing value: �. Path '', line 0, position 0.
  at Newtonsoft.Json.JsonTextReader.ParseValue () [0x002b3] in <12891e825fce44a581e5bbbb579c1d49>:0 
  at Newtonsoft.Json.JsonTextReader.Read () [0x0004c] in <12891e825fce44a581e5bbbb579c1d49>:0 
  at Newtonsoft.Json.JsonReader.ReadAndMoveToContent () [0x00000] in <12891e825fce44a581e5bbbb579c1d49>:0 
  at Newtonsoft.Json.JsonReader.ReadForType (Newtonsoft.Json.Serialization.JsonContract contract, System.Boolean hasConverter) [0x0004a] in <12891e825fce44a581e5bbbb579c1d49>:0 
  at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize (Newtonsoft.Json.JsonReader reader, System.Type objectType, System.Boolean checkAdditionalContent) [0x000db] in <12891e825fce44a581e5bbbb579c1d49>:0 
  at Newtonsoft.Json.JsonSerializer.DeserializeInternal (Newtonsoft.Json.JsonReader reader, System.Type objectType) [0x00054] in <12891e825fce44a581e5bbbb579c1d49>:0 
  at Newtonsoft.Json.JsonSerializer.Deserialize (Newtonsoft.Json.JsonReader reader, System.Type objectType) [0x00000] in <12891e825fce44a581e5bbbb579c1d49>:0 
  at Newtonsoft.Json.JsonConvert.DeserializeObject (System.String value, System.Type type, Newtonsoft.Json.JsonSerializerSettings settings) [0x0002d] in <12891e825fce44a581e5bbbb579c1d49>:0 
  at Newtonsoft.Json.JsonConvert.DeserializeObject[T] (System.String value, Newtonsoft.Json.JsonSerializerSettings settings) [0x00000] in <12891e825fce44a581e5bbbb579c1d49>:0 
  at Newtonsoft.Json.JsonConvert.DeserializeObject[T] (System.String value) [0x00000] in <12891e825fce44a581e5bbbb579c1d49>:0 
  at JsonParseTextRepro.ApiService.GetPun () [0x0013f] in <a23104cc471e42a78acea59e0c31e721>:0 
  at JsonParseTextRepro.App+DemoPage.OnAppearing () [0x00091] in <a23104cc471e42a78acea59e0c31e721>:0 

brminnick added a commit to xamarin/XamarinAzureChallenge that referenced this issue Sep 15, 2019
This is a workaround for the current preview channel of Visual Studio for Mac: dotnet/android#3626 (comment)
@brendanzagaeski
Copy link
Contributor

Internal cross-referencing link for the Microsoft team:

VS bug #987488

@brminnick
Copy link
Author

Thanks @brendanzagaeski

I confirmed that the work-around was successful for me 👍

To prevent the linker from removing the AndroidClientHandler library, I added it to the Ignore assembles option in the Android Build settings.

enter image description here

radekdoulik added a commit to radekdoulik/xamarin-android that referenced this issue Sep 25, 2019
Fixes: dotnet#3626

mono/mono@6034bc0
introduced new `HttpClient.CreateDefaultHandler()` method, which
replaces the `HttpClient.GetDefaultHandler()` method.

Our XA linker logic was detecting `AndroidClientHandler` usage by
checking the `GetDefaultHandler` method and so it doesn't work
anymore.
radekdoulik added a commit to radekdoulik/xamarin-android that referenced this issue Sep 26, 2019
Fixes: dotnet#3626

mono/mono@6034bc0
mono/mono@2d6f02a
introduced new `HttpClient.CreateDefaultHandler()` method, which
replaces the `HttpClient.GetDefaultHandler()` method.

Our XA linker logic was detecting `AndroidClientHandler` usage by
checking the `GetDefaultHandler` method and so it doesn't work
anymore.
radekdoulik added a commit to radekdoulik/xamarin-android that referenced this issue Sep 26, 2019
Fixes: dotnet#3626

mono/mono@6034bc0
mono/mono@2d6f02a
introduced new `HttpClient.CreateDefaultHandler()` method, which
replaces the `HttpClient.GetDefaultHandler()` method.

Our XA linker logic was detecting `AndroidClientHandler` usage by
checking the `GetDefaultHandler` method and so it doesn't work
anymore.
radekdoulik added a commit that referenced this issue Sep 27, 2019
Fixes: #3626

mono/mono@6034bc0
mono/mono@2d6f02a
introduced new `HttpClient.CreateDefaultHandler()` method, which
replaces the `HttpClient.GetDefaultHandler()` method.

Our XA linker logic was detecting `AndroidClientHandler` usage by
checking the `GetDefaultHandler` method and so it doesn't work
anymore.

Added a new test to avoid similar regression in the future.
jonpryor pushed a commit that referenced this issue Sep 27, 2019
Fixes: #3626

mono/mono@6034bc0
mono/mono@2d6f02a
introduced new `HttpClient.CreateDefaultHandler()` method, which
replaces the `HttpClient.GetDefaultHandler()` method.

Our XA linker logic was detecting `AndroidClientHandler` usage by
checking the `GetDefaultHandler` method and so it doesn't work
anymore.

Added a new test to avoid similar regression in the future.
@brendanzagaeski
Copy link
Contributor

Release status update

A new Preview version has now been published that includes the fix for this item. The fix is not yet included in a Release version. I will update this item again when a Release version is available that includes the fix.

Fix included in Xamarin.Android 10.1.0.1.

Fix included on Windows in Visual Studio 2019 version 16.4 Preview 2. To try the Preview version that includes the fix, check for the latest updates in Visual Studio Preview.

Fix included on macOS in Visual Studio 2019 for Mac version 8.4 Preview 1. To try the Preview version that includes the fix, check for the latest updates on the Preview updater channel.

@brendanzagaeski
Copy link
Contributor

Release status update

A new Release version has now been published on Windows that includes the fix for this item. The fix is not yet published in a Release version on macOS. I will update this item again when a Release version is available on macOS that includes the fix.

Fix included in Xamarin.Android 10.1.0.30.

Fix included on Windows in Visual Studio 2019 version 16.4. To get the new version that includes the fix, check for the latest updates or install the latest version from https://visualstudio.microsoft.com/downloads/.

(Fix also included on macOS in Visual Studio 2019 for Mac version 8.4 Preview 2.1 and higher. To try the Preview version that includes the fix, check for the latest updates on the Preview updater channel.)

@brendanzagaeski
Copy link
Contributor

Release status update

A new Release version has now been published on macOS that includes the fix for this item.

Fix included in Xamarin.Android 10.1.1.0.

Fix included on macOS in Visual Studio 2019 for Mac version 8.4. To get the new version that includes the fix, check for the latest updates on the Stable updater channel.

(Fix also included on Windows in Visual Studio 2019 version 16.4 and higher. To get the new version that includes the fix, check for the latest updates or install the latest version from https://visualstudio.microsoft.com/downloads/.)

@ghost ghost locked as resolved and limited conversation to collaborators Jun 5, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Area: Linker Issues when linking assemblies. regression
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants