Skip to content

VersionOperationsExtensions.GetCodeAsync throws an exception in AOT scenarios #1633

Closed

Description

@hach-que

Describe the bug
VersionOperationsExtensions.GetCodeAsync throws an exception in AOT scenarios.

Kubernetes C# SDK Client Version
16.0.2

Server Kubernetes Version
1.26.1

Dotnet Runtime Version
net9

To Reproduce
Install KubernetesClient.Aot, and then try to query the version information from Kubernetes:

var config = KubernetesClientConfiguration.BuildConfigFromConfigFile(configFile);

var kubernetes = new Kubernetes(config);

for (var i = 0; i < maximumWaitSeconds && !cancellationToken.IsCancellationRequested; i++)
{
    try
    {
        var code = await kubernetes.Version.GetCodeAsync(cancellationToken);
        _logger.LogInformation($"Connected to API server, Kubernetes is running version: {code.Major}.{code.Minor}");
        return kubernetes;
    }
    catch (HttpRequestException ex)
    {
        _logger.LogWarning($"Failed to connect to Kubernetes API server; it might still be starting up: {ex}");
        if (i < maximumWaitSeconds - 1)
        {
            await Task.Delay(1000, cancellationToken);
        }
    }
    cancellationToken.ThrowIfCancellationRequested();
}
cancellationToken.ThrowIfCancellationRequested();

This results in the following exception:

System.ArgumentNullException: Value cannot be null. (Parameter 'jsonTypeInfo')
    at System.Text.Json.ThrowHelper.ThrowArgumentNullException(String)
    at System.Text.Json.JsonSerializer.Deserialize(Stream, JsonTypeInfo)
    at k8s.KubernetesJson.Deserialize[TValue](Stream, JsonSerializerOptions )
    at k8s.Kubernetes.CreateResultAsync[T](HttpRequestMessage, HttpResponseMessage, Nullable`1, CancellationToken)
    at k8s.AbstractKubernetes.IVersionOperations_GetCodeWithHttpMessagesAsync[T](IReadOnlyDictionary`2, CancellationToken)
    at k8s.AbstractKubernetes.k8s.IVersionOperations.GetCodeWithHttpMessagesAsync(IReadOnlyDictionary`2, CancellationToken)
    at k8s.VersionOperationsExtensions.GetCodeAsync(IVersionOperations, CancellationToken )
    at Redpoint.KubernetesManager.Services.DefaultKubernetesClientFactory.ConnectToClusterAsync(String, Int32, CancellationToken)
    at Redpoint.KubernetesManager.Components.ControllerOnly.KubernetesClientComponent.OnStartedAsync(IContext context, IAssociatedData data, CancellationToken cancellationToken)
    at Redpoint.KubernetesManager.Signalling.Executor.<>c__DisplayClass12_1.<<RaiseSignalAsync>b__1>d.MoveNext()

Expected behavior
AOT should work.

Activity

  1. self-assigned this
    on May 22, 2025
  2. k8s-triage-robot commented on Aug 20, 2025

    @k8s-triage-robot

    The Kubernetes project currently lacks enough contributors to adequately respond to all issues.

    This bot triages un-triaged issues according to the following rules:

    • After 90d of inactivity, lifecycle/stale is applied
    • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
    • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

    You can:

    • Mark this issue as fresh with /remove-lifecycle stale
    • Close this issue with /close
    • Offer to help out with Issue Triage

    Please send feedback to sig-contributor-experience at kubernetes/community.

    /lifecycle stale

  3. added
    lifecycle/stale
    on Aug 20, 2025
  4. hach-que commented on Aug 21, 2025

    @hach-que
    Author

    Fixed by #1636 presumably.

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

Metadata

Metadata

Assignees

Labels

lifecycle/stale

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions