Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

For Unity, it seems that types containing Array and IEnumerable<> fields are not supported #376

Open
not502 opened this issue Feb 15, 2025 · 1 comment

Comments

@not502
Copy link

not502 commented Feb 15, 2025

My code is very simple

public class MyTest : MonoBehaviour
{
    void Start()
    {
        var _d = new TestData() { data = Encoding.UTF8.GetBytes(\"Hello World\") };
        MemoryPackSerializer.Serialize(_d);
    }

}

[MemoryPackable]
public partial class TestData
{
    public byte[] data;
}

But running in Unity will result in the following error message

MemoryPackSerializationException: TestData is not registered in this provider.
MemoryPack.MemoryPackSerializationException.ThrowNotRegisteredInProvider (System.Type type) (at <a3c91ce317d34ad180564c2b7f9a0687>:0)
MemoryPack.ErrorMemoryPackFormatter`1[T].Throw () (at <a3c91ce317d34ad180564c2b7f9a0687>:0)
MemoryPack.ErrorMemoryPackFormatter`1[T].Serialize[TBufferWriter] (MemoryPack.MemoryPackWriter`1[TBufferWriter]& writer, T& value) (at <a3c91ce317d34ad180564c2b7f9a0687>:0)
MemoryPack.MemoryPackWriter`1[TBufferWriter].WriteValue[T] (T& value) (at <a3c91ce317d34ad180564c2b7f9a0687>:0)
MemoryPack.MemoryPackSerializer.Serialize[T,TBufferWriter] (MemoryPack.MemoryPackWriter`1[TBufferWriter]& writer, T& value) (at <a3c91ce317d34ad180564c2b7f9a0687>:0)
MemoryPack.MemoryPackSerializer.Serialize[T] (T& value, MemoryPack.MemoryPackSerializerOptions options) (at <a3c91ce317d34ad180564c2b7f9a0687>:0)
MyTest.Start () (at Assets/Scripts/MyTest.cs:11)

In the test, I tested three types: byte[], int[], and List<byte>, all of which resulted in the above error message. I want to know if it's due to incorrect usage or some other reason. Additionally, this issue occurs in both of my projects.

@not502
Copy link
Author

not502 commented Feb 15, 2025

There is one more thing, I am using Unity2021.3 version (.NET Standard 2.1)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant