Brandon Minnick
Brandon Minnick

Reputation: 15340

Xamarin.Android: `Newtonsoft.Json.JsonReaderException`

Running the current Preview channel of Visual Studio Mac, v8.3 build 1630, my Xamarin.Android app reports a Newtonsoft.Json.JsonReaderException.

The code below works fine in the current Stable channel of Visual Studio for Mac, v8.2.6 (build 28).

Do I need to update something for VS for Mac v8.3?

Code

readonly static HttpClient _client = new HttpClient();

public static async Task<MyModel> GetModelFromApi()
{
    using (var response = await _client.GetAsync("https://my.api.url/endpoint").ConfigureAwait(false))
    {
        var json = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
        return JsonConvert.DeserializeObject<MyModel>(json);
    }
}

Stack Trace

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 

Environment Info

=== 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)

=== 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@6434153 Java.Interop: xamarin/java.interop@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@cb41333

Upvotes: 1

Views: 766

Answers (1)

Brandon Minnick
Brandon Minnick

Reputation: 15340

Answer

This is a regression in the Managed Linker where it is incorrectly removing the Xamarin.Android.Net.AndroidClientHandler library.

The Xamarin team is aware of the issue and you can track the status of it here: https://github.com/xamarin/xamarin-android/issues/3626

Work Around

To prevent the linker from removing the AndroidClientHandler library, you can add it to the Ignore assembles option in the Android Build settings.

enter image description here

Upvotes: 2

Related Questions