Xamarin.Android 上的 JsonSerializationException '无法找到构造函数' [英] JsonSerializationException 'Unable to find a constructor' on Xamarin.Android

查看:21
本文介绍了Xamarin.Android 上的 JsonSerializationException '无法找到构造函数'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的代码有一个非常奇怪的问题,这是一个相当新的问题,考虑到我半年前还没有这个问题.长话短说,我在 Xamarin 中制作了一个应用,并在大约半年前在所有 3 个商店(App Store、Google Play 和 Microsoft Store)上发布.

I have this very odd problem with my code, and it's a pretty new problem, considering I didn't have it half a year ago. Long story short, I've made an app in Xamarin, and released it about half a year ago, on all 3 stores (App Store, Google Play and Microsoft Store).

昨天有用户报告了 Android 应用程序的问题,在我修复并重新编译后,我现在遇到了 Json.NET 的新错误

Yesterday a user reported a problem with the Android app, and after I got that fixed and recompiled, I'm now encountering a new error with Json.NET

例外是

Newtonsoft.Json.JsonSerializationException: Unable to find a constructor to use for type Rowlog.Common.Dtos.CompressedTripData. A class should either have a default constructor, one constructor with arguments or a constructor marked with the JsonConstructor attribute. Path 'tripCoordinates', line 1, position 19.

在你问之前,是的 Rowlog.Common.Dtos.CompressedTripData 确实有一个无参数的构造函数(好吧,它根本没有,我们都知道这是同一回事).

And before you ask, yes Rowlog.Common.Dtos.CompressedTripData does indeed have a parameterless constructor (Well, it doesn't have one at all, which we all know is the same thing).

就像我说的,这是当我从 Android 设备上的服务器加载 CompressedTripData 对象时.在 iOS 和 Windows Phone 上加载完全相同的对象可以顺利进行.我猜这一定是 Json.NET 或 Xamarin.Android 最近发生的变化导致了这种情况(其他应用程序仍在使用大约半年前的 Json.NET 库.不确定是否有此后的任何更新)

And like I said, this is when I load a CompressedTripData object from the server on an Android device. Loading the exact same object on iOS and Windows Phone works without a hitch. I'm guessing it's gotta be a recent change in either Json.NET, or Xamarin.Android which is causing this (The other apps are still using the Json.NET libraries from about half a year ago. Not sure if there has even been any updates to it since)

有没有其他人遇到过类似的问题,如果有,你是如何解决的?

Has anyone else encountered a similar problem, and if so, how have you fixed it?

推荐答案

在项目属性的Android 选项"选项卡中,有一个链接器"选项卡.链接"下拉列表中的选定选项是仅限 Sdk 程序集"还是Sdk 和用户程序集"?

In the 'Android options' tab of the project properties, there is a 'linker' tab. Is the selected option in the 'Linking' dropdown "Sdk Assemblies only" or is it "Sdk and user assemblies"?

如果是后者,链接时会跳过无参构造函数,因为检测到没有使用.因此,将其更改为仅限 Sdk 程序集".

If it is the latter, the parameterless constructor is skipped when linking, because no use is detected. So change it to "Sdk Assemblies only".

这篇关于Xamarin.Android 上的 JsonSerializationException '无法找到构造函数'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆