Xamarin.Android上的JsonSerializationException'无法找到构造函数' [英] JsonSerializationException 'Unable to find a constructor' on Xamarin.Android
问题描述
我的代码有一个非常奇怪的问题,考虑到我半年前还没有,这是一个相当新的问题.长话短说,我已经在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库.不确定是否已经使用了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屋!