Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JsonConvert.DeserializeObjects does not work after Linking SDK and User Assemblies

The method JsonConvert.DeserializeObjects works when the Linking is set to SDK Assemblies Only but when I build the project using Link SDK and User Assemblies option in the Linker Properties, it does not work, it returns null in all the fields of the Deserialized object.

like image 466
Akash Amin Avatar asked May 09 '26 12:05

Akash Amin


1 Answers

You need to put the [Preserve(AllMembers = true)] attribute on any classes that are dynamically generated. This will prevent them from being stripped out.

You can read more on the iOS linker here.

So lets say you currently have a list of Users you want to deserialize you would say something like.

var user = JsonConvert.DeserializeObject<User>(json);

In your User class you will want to place the attribute over that class.

[Preserve(AllMembers = true)]
public class User{
  public string Email { get; set; }
  public string FirstName { get; set; }
  public string Lastname { get; set; }
}
like image 63
Andres Castro Avatar answered May 12 '26 13:05

Andres Castro