Skip to content

KubernetesJson.Serialize fails due to null JsonSerializerInfo for V1Patch #1587

Closed
@hwoodiwiss

Description

@hwoodiwiss

Describe the bug
It looks like SourceGenerationContext lacks JSON serialization metadata for the V1Patch type, which causes patch requests to fail in AOT scenarios.

Kubernetes C# SDK Client Version
15.0.1

Server Kubernetes Version
1.30.0

Dotnet Runtime Version
net9.0, though this is likely reproducible across AOT compatible TFM's

To Reproduce
Attempt to patch some k8s config using one of the Patch... methods on the Kubernetes client that takes V1Patch while using the Kubernetes.Aot package.

Expected behavior
Configuration to update successfully.

Where do you run your app with Kubernetes SDK (please complete the following information):

  • OS: Windows
  • Environment: Local (Desktop, ARM Laptop)
  • Cloud: No, local cluster

Additional context

I've fixed this in a local version of the package by just adding a second JsonSerializerContext just for V1Patch, and in KubernetesJson.Serialize checking both contexts for type info (commit):

var info = SourceGenerationContext.Default.GetTypeInfo(value.GetType()) ?? LocalSgContext.Default.GetTypeInfo(value.GetType());

I appreciate this is a suboptimal solution. Unfortunately I get build errors adding V1Patch to SourceGenerationContext.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions