Skip to content

Add Native AOT support for .NET 8+#394

Open
bbartels wants to merge 11 commits into
rajanadar:masterfrom
bbartels:master
Open

Add Native AOT support for .NET 8+#394
bbartels wants to merge 11 commits into
rajanadar:masterfrom
bbartels:master

Conversation

@bbartels

@bbartels bbartels commented Feb 20, 2026

Copy link
Copy Markdown

Summary

  • Add System.Text.Json source generation via VaultSharpJsonContext to enable Native AOT compilation on .NET 8+, replacing all anonymous types used as request payloads with strongly-typed models (AotRequestModels.cs) decorated with [JsonPropertyName] attributes
  • Switch serialization/deserialization calls to use JsonTypeInfo-based overloads on .NET 8+ (via #if NET8_0_OR_GREATER) while preserving reflection-based fallback for older target frameworks
  • Update all [JsonConverter(typeof(JsonStringEnumConverter))] enum attributes to use the AOT-compatible generic JsonStringEnumConverter on .NET 8+
  • Refactor VaultApiException to use JsonDocument-based parsing instead of JsonSerializer.Deserialize<Dictionary<string, IEnumerable>>, avoiding reflection
  • Remove unnecessary [JsonDerivedType] attributes from AbstractAuditBackend (already handled by custom AuditBackendJsonConverter) and add missing [JsonPropertyName("type")] to audit backend subtypes
  • Expose JsonSerializerOptions on VaultClientSettings to allow consumers to register custom type resolvers (e.g., for KV secret data types)

@bbartels

Copy link
Copy Markdown
Author

@rajanadar If you get a chance to take a look! Would be great to expand with support across the dotnet ecosystem. We have some apps using Vaultsharp which we'd love to publish as AOT instead

@bbartels

bbartels commented Apr 8, 2026

Copy link
Copy Markdown
Author

@rajanadar Gentle ping on this :)

@ajacques

Copy link
Copy Markdown

+1 on AOT support. Importing a library that doesn't support AOT prevents the entire application from being able to enable AOT.

@stevefan1999-personal

Copy link
Copy Markdown

@bbartels Can I take your code and hard fork a new project? The name for VaultSharp will be changed to something else though

@bbartels

Copy link
Copy Markdown
Author

Feel free :)

@bbartels

bbartels commented Jul 4, 2026

Copy link
Copy Markdown
Author

@ezhevita @rajanadar @SergeyFilippov @hoerup Would be great to get a review :) It's not that AOT is necessary for VaultSharp itself, its more than any libraries that take a dependency on VaultSharp are blocked from proper AOT support. (This is our case for some internal libraries)

Copilot AI and others added 2 commits July 4, 2026 14:49
- Fix enum JsonConverter attributes to use generic JsonStringEnumConverter<T>
  under NET8_0_OR_GREATER for AOT safety (IssuerFormat, IssuerPrivateKeyFormat,
  PrivateKeyType, PrivateKeyRoleType), with non-generic fallback for older TFMs
- Rename IssuerPrivetKeyFormat.cs -> IssuerPrivateKeyFormat.cs (typo fix)
- Add JsonSerializable registrations in VaultSharpJsonContext for all new PKI
  Issuers/Keys/Roles request and response types; use TypeInfoPropertyName to
  disambiguate KeysData and KeyInfo which exist in both Issuers and Keys namespaces
Extend Native AOT support for PKI management APIs
@SergeyFilippov

Copy link
Copy Markdown
Contributor

@bbartels unfortunately i can't help you with getting approval, but majority of changes align perfectly with resolving limitation/requirement of AOT compilation and operation (as per PR description).

One single question I have is about .csproj file: you are overriding titles there, for the target frameworks that not yet supported (and if supported - should be added in a separate PR). Is this some missed leftovers from an internally supported version of this library?

Comment thread src/VaultSharp/VaultSharp.csproj Outdated
@bbartels

Copy link
Copy Markdown
Author

@bbartels unfortunately i can't help you with getting approval, but majority of changes align perfectly with resolving limitation/requirement of AOT compilation and operation (as per PR description).

One single question I have is about .csproj file: you are overriding titles there, for the target frameworks that not yet supported (and if supported - should be added in a separate PR). Is this some missed leftovers from an internally supported version of this library?

Fair point, removed those lines, thanks for the review!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants