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

Bug: Deserializing HashSet<T> fails #79

Open
klootas opened this issue Jan 27, 2021 · 3 comments
Open

Bug: Deserializing HashSet<T> fails #79

klootas opened this issue Jan 27, 2021 · 3 comments
Labels
bug Something isn't working

Comments

@klootas
Copy link

klootas commented Jan 27, 2021

It seems that deserializing a class with a property of type HashSet yields the following runtime exception in WebGL:

ArgumentNullException
value cannot be null
parameter name: method

Changing it to a List works though.

@klootas klootas added the bug Something isn't working label Jan 27, 2021
@applejag
Copy link
Owner

Hi @klootas, thanks for reporting this. I haven't really considered HashSets.

I'll have to look into this, but in the meantime you might find some answers here: #51 (comment), I believe it's related.

@fahall
Copy link

fahall commented Feb 23, 2021

In my project, I (de)serialized HashSets successfully in Engine, Windows, MacOS, and iOS. But, when I build for Android with IL2CPP, I get the error above.

@applejag
Copy link
Owner

Hi @fahall! Do you have access to the errors you receive?

You may be able to workaround it by adding such a script to your project: (does not need to be added to any GameObject)

using System;
using System.Collections.Generic;
using UnityEngine;
using Newtonsoft.Json.Utilities;

public class AotTypeEnforcer : MonoBehaviour
{
    public void Awake()
    {
        AotHelper.EnsureList<MyHashSetType>();
        AotHelper.Ensure(() =>
        {
            _ = new HashSet<MyHashSetType>(new MyHashSetType[0]);
        });
    }
}

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants