adam-dot-cohen / HyperSerializer

Dot Net Binary Serializer - 17x faster than Protobuf and Messagepack, 2x faster than MemoryPack
Apache License 2.0
66 stars 5 forks source link

HS throws a compile error when a class instance contains complex Type #2

Closed billwoo closed 1 year ago

billwoo commented 1 year ago

error at: Span bytes = HyperSerializer.Serialize(stree);

System.TypeInitializationException: 'The type initializer for 'Hyper.HyperSerializer`1' threw an exception.'

InnerException: Compilation failed, first error is: CS7036: There is no argument given that corresponds to the required formal parameter 'name' of 'SimpleTree.SimpleTree(string, string)';

'name' is used in the ctor, but there is no use of any (string, string)

adam-dot-cohen commented 1 year ago

@billwoo - The complex type property should be ignored during serialization per the Read Me. Is the type a struct without a default constructor? If you can post some sample code to reproduce, I'll take a look.

billwoo commented 1 year ago

Thanks, Adam, It is a tree structure where there is a collection of nodes (root nodes), and each node has a collection of nodes and, each node has a reference to the tree.

fyi: i am able to serialize this with DataContractSerializer by decorating the Node class with

[DataContract(IsReference = true)]

of course, the xml output is bloated as only MS can do: so, I run GZip and get as file reduction of > 75%

ye old BinarySerializer can also handle this with less decoration, bur, ad you know, it's deprecated nwow.

i've been trying other (non MS) serializers just to see what's possible/

cheers, Bill

On Tue, Oct 11, 2022 at 11:55 PM Adam Cohen @.***> wrote:

@billwoo https://github.com/billwoo - The complex type property should be ignored during serialization per the Read Me. Is the type a struct without a default constructor? If you can post some sample code to reproduce, I'll take a look.

— Reply to this email directly, view it on GitHub https://github.com/adam-dot-cohen/HyperSerializer/issues/2#issuecomment-1274998048, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAOQCXW2W7GLUYOS7L3JY2DWCWLZLANCNFSM6AAAAAARAUJLRA . You are receiving this because you were mentioned.Message ID: @.***>

--


«Reality is that which, when you stop believing in it, doesn’t go away» Philip K. Dick

adam-dot-cohen commented 1 year ago

HyperSerializer does not support heap based reference types or collections containing heap based reference types (see Read Me > Limitations) at this time. I've been meaning to support for complex types / full object graph, but haven't gotten around to it.

If you want to take a crack at adding support, let me know. Happy to collaborate and work on it with you. Basically need to update CodeGeneratorV3 and CodeSnippetsV3 and add calls to HyperSerializer.Serialize/Deserialize inside the generated class (from CodeSnippetsV3) so the library uses itself when it encounters complex types.

adam-dot-cohen commented 1 year ago

Closing the issue as the desired functionality is not supported at this time