Skip to content

Support AOT compilation #8031

Closed
Closed
@mcdis

Description

@mcdis

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:

  1. Create csproj and enable NativeAot ( true )
  2. 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; }
}
  1. Try IndexAsync(new ElasticSearchLogEntry());
  2. 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()

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions