Closed
Description
Elastic.Clients.Elasticsearch version: 8.12.0
.NET runtime version: v8.0.101
Operating system version: Windows 11
Description of the problem including expected versus actual behavior:
When NativeAOT mode is enabled, data cannot be sent and an exception is thrown. Setting the TypeInfoResolver in JsonSerializerOptions does not help since the execution does not reach the serializer.
Steps to reproduce:
- Create csproj and enable NativeAot ( true )
- Create document type with Native Aot serialization (System Json Source Generation) compatible:
[JsonSourceGenerationOptions(UseStringEnumConverter = true,
PropertyNamingPolicy = JsonKnownNamingPolicy.CamelCase)]
[JsonSerializable(typeof(ElasticSearchLogEntry))]
public partial class ElasticSearchLogEntryContext : JsonSerializerContext;
public class ElasticSearchLogEntry
{
public static ElasticSearchLogEntryContext Context => ElasticSearchLogEntryContext.Default;
public int Level { get; init; }
public int Priority { get; init; }
public string Scope { get; init; }
public long Timestamp { get; init; }
public string Description { get; init; }
}
- Try IndexAsync(new ElasticSearchLogEntry());
- Exception:
InvalidOperationException: Reflection-based serialization has been disabled for this application. Either use the source generator APIs or explicitly configure the 'JsonSerializerOptions.TypeInfoResolver' property.
StackTrace:
at Elastic.Transport.DefaultHttpTransport`1.ThrowUnexpectedTransportException[TResponse](Exception killerException, List`1 seenExceptions, RequestData requestData, TResponse response, RequestPipeline pipeline)
at Elastic.Transport.DefaultHttpTransport`1.<RequestCoreAsync>d__19`1.MoveNext()
at Elastic.Clients.Elasticsearch.ElasticsearchClient.<>c__DisplayClass28_0`3.<<DoRequestCoreAsync>g__SendRequest|0>d.MoveNext()
at App.Logging.ElasticSearch.ElasticSearchLogListener.<>c__DisplayClass3_1.<<-ctor>b__1>d.MoveNext()