Reproduction sample: https://github.com/brminnick/JsonParseTextRepro/
JsonParseTextRepro.slnNewtonsoft.Json.JsonReaderExceptionThe JSON should parse successfully, no exception should be thrown, displaying Success on the screen.
Newtonsoft.Json.JsonReaderException is thrown.
JsonParseTextRepro.slnSuccess=== 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/2019-06@6434153d8b7
Java.Interop: xamarin/java.interop/d16-3@5836f58
LibZipSharp: grendello/LibZipSharp/d16-3@71f4a94
LibZip: nih-at/libzip/rel-1-5-1@b95cf3f
ProGuard: xamarin/proguard/master@905836d
SQLite: xamarin/sqlite/3.27.1@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
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:
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
Internal cross-referencing link for the Microsoft team:
VS bug #987488
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.
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.)
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/.)