MemoryPack icon indicating copy to clipboard operation
MemoryPack copied to clipboard

Dictionary<string,byte[]> formatter is being trimmed with PublishAot

Open dusrdev opened this issue 11 months ago • 5 comments

Seems that the formatter that is being used internally in MemoryPack for Serialize(Dictionary<string,byte[]) is being trimmed, and the use of such object is now entirely broken.

Screenshot 2024-03-28 at 16 03 06

dusrdev avatar Mar 28 '24 14:03 dusrdev

Is there any update?

I have even attempted to somehow extract and create an instance of the required formatter myself, as I know the types at design time, but it has proven to be very difficult since a lot of the api's require use of inaccessible internal MemoryPack types/properties...

I'd even settle for a workaround, specifically for Dictionary<string, byte[]>, without this my entire app is broken...

dusrdev avatar Apr 09 '24 13:04 dusrdev

Maybe you can put following code somewhere to prevent trimming.

MemoryPackFormatterProvider.RegisterDictionary<Dictionary<string, byte[]>, string, byte[]>();

Or use a MemoryPackable(GenerateType.Collection) type that extends from Dictionary<string, byte[]>.

meryuhi avatar Apr 21 '24 05:04 meryuhi

Maybe you can put following code somewhere to prevent trimming.

MemoryPackFormatterProvider.RegisterDictionary<Dictionary<string, byte[]>, string, byte[]>();

Or use a MemoryPackable(GenerateType.Collection) type that extends from Dictionary<string, byte[]>.

The formatters for IMemoryPackable<T> implementing types are also being trimmed. Is looks like it is possible to register the formatters like you noted, but with many types, it seems verbose, and should probably happen automatically, this is the entire idea behind the attributes I assume...

dusrdev avatar Apr 21 '24 11:04 dusrdev

Yes, it should happen automatically as you said, registering the formatters manually is just a workaround. I guess it could be solved by #251...

meryuhi avatar Apr 21 '24 14:04 meryuhi