Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deserialize issue with JSON.NET on UWP, using ImmutableList (only Release mode)

I'm experiencing one of these annoying and strange behaviors which differs between Debug and Release mode. So, we're on UWP 10.0.10586, using JSON.NET 7.0.1

I've a model class that looks like this:

[JsonObject]
public class RootObject
{
    [JsonProperty]
    public Profile ProfileInfo { get; set; } = new Profile();

    [JsonProperty]
    public ImmutableList<Info> AdditionalInfo { get; set; } = ImmutableList.Create<Info>();
}

Then I try to deserialize a json:

var rootObject = JsonConvert.DeserializeObject<RootObject>(json);

This works perfectly in Debug mode, but doesn't deserialize AdditionalInfo when in Release mode (the list is null).

It also works if I use IEnumerable or IList instead of ImmutableList, but I wonder if there's a reason for this behavior or if is maybe a JSON.NET bug.

like image 512
Tommaso Scalici Avatar asked Mar 14 '23 19:03

Tommaso Scalici


1 Answers

Most likely you are hitting one of the runtime exceptions from .NET Native. To properly diagnose this I'd recommend enabling .NET Native compilation for the DEBUG configuration of your project (Project properties > BUILD > Enable .Net Native checkbox). Then, set your debugger to stop on first chance exceptions.

Now when you run you'll probably see a MissingMetadataException or somethign about serialization but because you're in DEBUG you'll get decent exception strings. If you can move to Update 1, the messages are a bit better. Most likely you'll need to add something to your Default.rd.xml file.

like image 178
MattWhilden Avatar answered Apr 06 '23 20:04

MattWhilden