You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When trying to use this library in a native AoT context, I get the following error:
System.NotSupportedException: 'Dahomey.Cbor.Serialization.Converters.ObjectConverter`1[]' 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
at System.Reflection.Runtime.General.TypeUnifier.WithVerifiedTypeHandle(RuntimeConstructedGenericTypeInfo, RuntimeTypeInfo[]) + 0x75
at Dahomey.Cbor.Serialization.Converters.Providers.ObjectConverterProvider.GetConverter(Type, CborOptions) + 0xe2
at System.Linq.Enumerable.SelectEnumerableIterator`2.MoveNext() + 0x74
at System.Linq.Enumerable.TryGetFirst[TSource](IEnumerable`1, Func`2, Boolean&) + 0x7c
at Dahomey.Cbor.Serialization.Converters.CborConverterRegistry.CreateConverter(Type type) + 0xbd
at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey, Func`2) + 0xa4
at Dahomey.Cbor.Serialization.Converters.CborConverterRegistry.Lookup[T]() + 0x25
at Dahomey.Cbor.Cbor.Serialize[T](T, IBufferWriter`1&, CborOptions) + 0x58
at Dahomey.Cbor.Cbor.SerializeAsync[T](T, Stream, CborOptions, CancellationToken) + 0x80
One solution would be to register types via CborSerializable with a CborContext, the same way it is done for System.Text.Json. See the example for reference:
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...
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.
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:The text was updated successfully, but these errors were encountered: