Closed dameng324 closed 7 months ago
Maybe the main point is here. dotnet -c Release has reflection metadata. but NativeAOT has not.
static method is not invoked at dotnet run -c Release
, the TryInvokeRegisterFormatter
method invoked.
It looks like a MemoryPack issue not NativeAOT runtime bug.
Hello. Thanks for the report.
It seems that if there is no Serialize in the source code and only Deserialize, the AOT build will trim the required code.
In #237, As a quick workaround, we have addressed this issue by adding [DynamicallyAccessedMembers].
It is difficult to completely remove reflection from a MemoryPack implementation. Therefore, we are currently unable to even turn off all the AOTwarnings that the compiler produces.
But for the time being, adding attribute seems to work in most cases.
Next release should be coming soon. Please let us know if there are any more problems. Thanks again.
Thanks for your work. It looks useful in the case.
I wonder Deserialize<ICollection<MemPackTestObj>>
will work or not. I'll try until have some time to do it.
I wonder Deserialize<ICollection
> will work or not. I'll try until have some time to do it.
I have tried and it works. Looks very nice.
I found the main issue is The T's static constructor does not Invoke when
Deserialize<T>
when NativeAOT. so there is no formatter registered. If I addvar r = new MemPackTestObj() { Strings = new[] { "a", "b", "c" } };
before Deserialize, It works.Code:
csproj
When
dotnet run -c Release
It works as expected.When
dotnet publish -c Release
and.\bin\Release\net8.0\win-x64\publish\NativeAot.exe
Is this a NativeAOT runtime bug? any solution to solve this?