- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我在部署的系统上收到以下错误:
See the end of this message for details on invoking
just-in-time (JIT) debugging instead of this dialog box.
************** Exception Text **************
Newtonsoft.Json.JsonReaderException: Unexpected character encountered while parsing value: S. Path '', line 0, position 0.
at Newtonsoft.Json.JsonTextReader.ParseValue()
at Newtonsoft.Json.JsonTextReader.ReadInternal()
at Newtonsoft.Json.JsonTextReader.Read()
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.ReadForType(JsonReader reader, JsonContract contract, Boolean hasConverter)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent)
at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType)
at Newtonsoft.Json.JsonConvert.DeserializeObject(String value, Type type, JsonSerializerSettings settings)
at Newtonsoft.Json.JsonConvert.DeserializeObject[T](String value, JsonSerializerSettings settings)
at JsonWrapper.DeserializeJson[T](String data, ITraceWriter tracer)
这是来自 DLL 的简化 JsonWrapper.DerserializeJson 代码:
public static T DeserializeJson<T>(string data, ITraceWriter tracer) {
try {
return JsonConvert.DeserializeObject<T>(data, new JsonSerializerSettings { TraceWriter = tracer });
} catch (JsonReaderException jrex) {
throw new CustomException("Unable to deserialize Json message.", jrex);
}
}
我知道为什么抛出异常,但是我无法弄清楚为什么它没有被 try-catch block 捕获。
此代码是我们的一位客户正在使用的 DLL。我希望这是一个可以单独在 DLL 中完成的修复。
任何对此的见解都会很棒!
最佳答案
您的 JsonException 可能来源于另一个程序集。
如果您的 Newtonsoft 版本与其他程序集中的版本不同,特定的 catch block 将不会捕获它(通用异常捕获会)。
解决方案是使用相同版本的 Newtonsoft。
dbc 在评论中提到了这一点。
关于c# - 无法捕获 JsonReaderException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34234433/
我在部署的系统上收到以下错误: See the end of this message for details on invoking just-in-time (JIT) debugging ins
我有一个使用 Angular 和 C# 的网络项目。 在 C# Controller 中,我想读取用于测试的本地 json 文件的内容。 这是我运行的代码,用于从我的工作目录中读取 JSON。 str
我有这段代码来尝试打开一个 .json 文件并读取它: [Route("{unit}/{begindate}")] public string Get(string unit, string begi
主程序中的代码 controller.modelToFile("passwords/test.json"); controller.deJSONizeModel("passwords/test.jso
我在 header 中请求 gZip 响应,例如: request.Headers.Add(HttpRequestHeader.AcceptEncoding, "gzip"); 在 webrespon
我在全息镜头上部署时遇到异常。我不知道为什么或如何解决它。它发生在下面的类中。 class JsonConverter { public Dictionary convertJsonToObj
上下文 - 我们的代码 我们在重定向 API Http GET 调用时遇到错误。我在 stackoverflow 上搜索了类似的问题,但它似乎不像我们的问题。 我们有一个简单的场景。我们的解决方案是作
我遵循了那里的教程,并且想出了这个...... 它是一种设备注册方法,使用 Microsoft.WindowsAzure.MobileServices.MobileServiceClient.Regi
正在尝试连接 JOliver's EventStore与 RavenDB并遇到障碍。我在 Raven 中创建了一个名为 RavenEventStore 的新数据库。 以下是我的线路; return W
我正在尝试制作一个 discord 机器人,但我在连接到 discord API 时遇到问题。我正在使用 visual studio community 2019。我使用 .net 核心控制台应用程序
我正在尝试用 C# 编写 AWS Lambda 函数。我有 AWS Toolkit for Visual Studio 2015。我使用 AWS Lambda 项目 (.Net Core) 创建了一个
反序列化命令时,我们遇到随机异常。我们有一个仅发送 API,可将消息放入队列中。尝试使用消息但失败。无论消息类型如何,它都会随机发生。有时后端可以反序列化消息。我们将 NServiceBus 设置为使
我正在尝试将一些日期插入到我的本地数据库中。我收到一个错误: {Newtonsoft.Json.JsonReaderException: Could not convert string to Dat
反序列化命令时,我们遇到随机异常。我们有一个仅发送 API,可将消息放入队列中。尝试使用消息但失败。无论消息类型如何,它都会随机发生。有时后端可以反序列化消息。我们将 NServiceBus 设置为使
我正在尝试将一些日期插入到我的本地数据库中。我收到一个错误: {Newtonsoft.Json.JsonReaderException: Could not convert string to Dat
我们已将 Newtonsoft.Json 从 10.0.3 升级到 11.0.1,之前可以运行的代码不再运行。 我们有以下 JSON: [{"mail-type":"registration","re
我在解析包含 JSON 的字符串时收到此异常: Newtonsoft.Json.JsonReaderException: Unterminated string. Expected delimiter
您好,我正在尝试从移动后端调用 lambda 函数。 我使用.Net Core生成了Lambda函数 public string FunctionHandler(string text,
我有以下字符串。我收到以下错误。你能告诉我哪里出了问题吗? Unexpected character encountered while parsing value: C. Path '', line
我正在运行下面的代码来故意抛出 JsonReaderException。它正确地给出了“无法将字符串转换为 bool 值:aaa。路径‘事件’,第 3 行,位置 17”的异常消息。 有什么方法可以直接
我是一名优秀的程序员,十分优秀!