Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JsonConvert.SerializeObject always return {} in XamarinForms

JsonConvert.SerializeObject seems to be not working in xamarin forms. Or i might be missing something here. Here is the output when i serialize a simple object. enter image description here

See it returns {}. I tried serializing a class also and it did return the same.

What could be the problem here?

UPDATE

Still no solution to this issue. I tried creating a simple console application and serializeObject is working on that project so i assume it is not working in xamarin forms only. Does anybody have a xamarin forms project where JSON.NET's serializeobject is working?

I am using visual studio 2017, json.net 10.0.3 and live player.

like image 226
Voltaire John Secondes Biton Avatar asked Dec 31 '17 10:12

Voltaire John Secondes Biton


2 Answers

This is a known problem see https://developer.xamarin.com/guides/cross-platform/live/limitations/

Limited support for reflection (currently affects some popular NuGets, like SQLite and Json.NET). Other NuGets are still supported.

If you compile it to an APK it works fine on the actual device.

Also posted an issue here: https://github.com/JamesNK/Newtonsoft.Json/issues/1578

like image 139
user277754 Avatar answered Sep 23 '22 18:09

user277754


I tried setting up emulator on a fast machine and the serialize works! So it means it doesn't work when i run it on live player using my android phone. I will set this as an answer for now. if someone else posted on how to make it work on live player, i will set it as the correct answer

like image 28
Voltaire John Secondes Biton Avatar answered Sep 24 '22 18:09

Voltaire John Secondes Biton