【问题标题】:Xamarin.Android: `Newtonsoft.Json.JsonReaderException`Xamarin.Android:`Newtonsoft.Json.JsonReaderException`
【发布时间】:2020-01-18 14:43:44
【问题描述】:

运行 Visual Studio Mac 的当前预览频道,v8.3 build 1630,我的 Xamarin.Android 应用报告了 Newtonsoft.Json.JsonReaderException

以下代码在 Visual Studio for Mac v8.2.6(内部版本 28)的当前 Stable 通道中运行良好。

我需要为 VS for Mac v8.3 更新一些内容吗?

代码

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);
    }
}

堆栈跟踪

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 

环境信息

=== Visual Studio Enterprise 2019 for Mac(预览版)===

8.3 版预览版(8.3 build 1630) 安装UUID:6e5142b4-e8be-4d1c-b75e-4744b0d8c3de GTK+ 2.24.23(罗利主题) Xamarin.Mac 5.16.1.24 (d16-3 / 08809f5b)

=== Xamarin.Android ===

版本:10.0.0.40(Visual Studio 企业版) 提交:xamarin-android/d16-3/080eaac Android SDK:/Users/brandonm/Library/Developer/Xamarin/android-sdk-macosx 支持的安卓版本: 没有安装

SDK 工具版本:26.1.1 SDK平台工具版本:28.0.2 SDK 构建工具版本:28.0.3

构建信息: 单声道:单声道/单声道@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 工具:xamarin/xamarin-android-tools@cb41333

【问题讨论】:

    标签: xamarin.android visual-studio-mac


    【解决方案1】:

    回答

    这是托管链接器中的回归,它错误地删除了Xamarin.Android.Net.AndroidClientHandler 库。

    Xamarin 团队已意识到该问题,您可以在此处跟踪它的状态: https://github.com/xamarin/xamarin-android/issues/3626

    解决方法

    为防止链接器删除AndroidClientHandler 库,您可以将其添加到Android Build 设置中的Ignore assembles 选项中。

    【讨论】:

      猜你喜欢
      • 2018-07-12
      • 1970-01-01
      • 1970-01-01
      • 2019-11-10
      • 1970-01-01
      • 2015-06-13
      • 2021-02-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多