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
{{ message }}
Repository navigation
CoreSync.Http.Client fails under NativeAOT: reflection-based System.Text.Json and MessagePack Typeless/contractless resolvers #22
We sync a .NET 11 iOS app (NativeAOT, PublishAot=true) through CoreSync.Http.Client 0.1.129 + CoreSync.Sqlite 0.1.129. Under CoreCLR it works; under NativeAOT the first sync fails after the local GetChanges with SynchronizationException wrapping NotSupportedException:
'System.Text.Json.Serialization.Converters.DictionaryOfTKeyTValueConverter`3[
System.Collections.Generic.Dictionary`2[System.String,System.Int32],System.String,System.Int32]'
is missing native code or metadata.
Cause: SyncProviderHttpClient uses PostAsJsonAsync / ReadFromJsonAsync<T> without a JsonTypeInfo, so System.Text.Json builds converters by reflection (BulkSyncChangeSet.ChangesByTable is Dictionary<string, int>). NativeAOT has no code for value-type generic instantiations it did not see at compile time.
We worked around it in the app by declaring a source-generated JsonSerializerContext for BulkSyncChangeSet, BulkChangeSetUploadItem, SyncAnchor, SyncVersion and SyncItem[] that is never used, only so the compiler emits those instantiations. With that, a full download (143 rows) succeeded under NativeAOT.
The second risk is CoreSyncMessagePackSerializer.Options = TypelessContractlessStandardResolver.Options: MessagePack's dynamic resolvers generate IL at run time (not available under NativeAOT), and Typeless resolves types by name. Our runs used the JSON path, so we have not hit it yet; we expect bulk upload/download through MessagePack to fail the same way.
Suggestions
Accept a JsonSerializerOptions/IJsonTypeInfoResolver in SyncProviderHttpClientOptions (or ship a source-generated CoreSyncJsonContext for the HTTP DTOs) and pass JsonTypeInfo to the *AsJsonAsync calls.
Offer an AOT-safe MessagePack configuration (source-generated formatters via MessagePack v3's analyzer/generator, or a non-Typeless contract for SyncItem values), keeping wire compatibility with existing servers and clients.
Mark the assemblies IsAotCompatible once the warnings are gone.
Activity