Skip to content
This repository has been archived by the owner on Oct 6, 2023. It is now read-only.

Help: Getting "JsonSerializationException: Unable to find a constructor to use" error when trying to deserialize on WebGL #68

Answered by JesseDunlap
JesseDunlap asked this question in Q&A
Discussion options

You must be logged in to vote

Hopefully I can answer my own question here. This turned out to be because Unity strips constructors and type parameters during the linking phase if they're not used. In order to negate this, you can use the Preserve attribute or a link.xml file.

Adding [Preserve] attributes to my DTO class and its fields solved the issue.

[Preserve]
public class AccessTokenDto
{
    [Preserve]
    public string Token { get; set; }

    [Preserve]
    public DateTime ExpiresAt { get; set; }
    
    [Preserve]
    public DateTime CreatedAt { get; set; }
}

This may be something worthwhile adding to the README or Wiki. I'd be happy to do so if someone would like to point me to the right place to do it. Tha…

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by applejag
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #68 on December 10, 2020 11:13.