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

NativeAOT compatibility: publish warnings and how to make MemoryPack fully NativeAOT compatible? #211

Closed
xiaoyuvax opened this issue Jan 5, 2024 · 1 comment

Comments

@xiaoyuvax
Copy link

xiaoyuvax commented Jan 5, 2024

when publish with NATIVEAOT, following warnings thrown, does it matter?

Assembly 'MemoryPack.Core' produced AOT analysis warnings.
Assembly 'MemoryPack.Core' produced trim warnings. For more information see https://aka.ms/dotnet-illink/libraries

during runtime (seems built-in types were trimmed):

System.Collections.Generic.IDictionary2[[System.String, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[MyType] is failed in provider at creating formatter. 'MemoryPack.Formatters.InterfaceDictionaryFormatter2[MyType]' is missing native code or metadata. This can happen for code that is not compatible with trimming or AOT. Inspect and fix trimming and AOT related warnings that were generated when the app was published. For more information see https://aka.ms/nativeaot-compatibility

Can MemoryPack be sured to be nativeaot compaitible?

@xiaoyuvax xiaoyuvax changed the title NATIVEAOT publish warnings NativeAOT publish warnings, how to make MemoryPack be fully NativeAOT compatible? Jan 29, 2024
@xiaoyuvax xiaoyuvax changed the title NativeAOT publish warnings, how to make MemoryPack be fully NativeAOT compatible? NativeAOT publish warnings, how to make MemoryPack fully NativeAOT compatible? Jan 29, 2024
@xiaoyuvax xiaoyuvax changed the title NativeAOT publish warnings, how to make MemoryPack fully NativeAOT compatible? NativeAOT compatibility: publish warnings and how to make MemoryPack fully NativeAOT compatible? Jan 30, 2024
@hadashiA
Copy link
Contributor

Hello.
Currently, MemoryPack uses reflection in part to resolve Formatter. Therefore, it is not able to fully pass the AOT check by the compiler.

However, Try the version after #237 is merged.
For example, the following code you are concerned about worked with NativeAOT on my end.

var dict = new Dictionary<string, MyType>
{
    { "a", new MyType { X = 100 } }
};

var bin = MemoryPackSerializer.Serialize(dict);
var d = MemoryPackSerializer.Deserialize<IDictionary<string, MyType>>(bin)!;
System.Console.WriteLine(d["a"].X);

[MemoryPackable]
partial class MyType
{
    public int X { get; set; }
}

If you have specific problematic code, please let us know, and I welcome a reopen.

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

2 participants