Open Odonno opened 5 months ago
Hi @Odonno,
Dahomey.Cbor is heavily based on reflexion that kind of generates code at runtime. For instance Expression trees are used at some places. It is absolutely not compatible with AOT.
AFAIK, System.Text.Json is using Source generators to generate code at compile time instead of reflexion at runtime. By this way, it is compatible with AOT.
It would require a full rewrite of multiple core parts of Dahomey.Cbor, especially the ObjectConverter class.
I'm not ready to follow this path at the moment...
Cheers,
Michaël
Hello Michaël,
Indeed, System.Text.Json
is using Source Generators to avoid the use of Reflection. This has to be the inspiration for this library, having attributes like CborSourceGenerationOptions
and CborSerializable
to generate the necessary code.
Like you said, this can require a lot of effort to support it, especially if you rely heavily on Reflection. That can be a long term goal to make it fully compatible.
Thank you for your response.
When trying to use this library in a native AoT context, I get the following error:
One solution would be to register types via
CborSerializable
with aCborContext
, the same way it is done forSystem.Text.Json
. See the example for reference: