You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Internal class IntOrStringJsonConverter doesn't work with System.Text.Json Source Generator #1535
I know the C# k8s client has been working to get compatible with source trimming. I tried to get Json serialization working, but get this error at compile time:
The 'JsonConverterAttribute' type 'k8s.Models.IntOrStringJsonConverter' specified on member 'k8s.Models.IntstrIntOrString' is not a converter type or does not contain an accessible parameterless constructor.
Kubernetes C# SDK Client Version 13.0.11
Dotnet Runtime Version
net6
To Reproduce
This snippet is enough for me to hit the warning along with adding <IsTrimmable>true</IsTrimmable> to my library project
This shouldn't raise an error. InOrStringJsonConverter is internal so making it public would likely fix the issue, but I'll leave that up to you if that's the best fix or not.
A little more context here would be that for some code paths, we log the json dump of the object that we're applying to the cluster so this doesn't affect the Client itself per se but would be nice for some of the observability things we do.
So more generally, then I guess the ask is that either the appropriate converters + models are public, or that the associated source generator metadata can be made public enough for us to use them outside of the K8s Client itself
I fixed this in, #1311 but it was closed. I would also like this PR to be completed, as I would like the performance benefits but don't plan on using full AOT.
Hi @tg123, thank you for following up, I tried switching to the Aot lib and that doesn't make the error go away. Here's my Program.cs.
usingSystem.Text.Json.Serialization;usingk8s.Models;// See https://aka.ms/new-console-template for more informationConsole.WriteLine("Hello, World!");[JsonSourceGenerationOptions(WriteIndented=true)][JsonSerializable(typeof(V1Pod))]internalpartialclassSourceGenerationContext:JsonSerializerContext{}
And the errors from dotnet publish -r win-x64
Q:\src\K8sTest\Program.cs(9,24): warning SYSLIB1220: The 'JsonConverterAttribute' type 'k8s.Models.ResourceQuantityJsonConverter' specified on member 'k8s.Models.ResourceQuantity' is not a converter type or does not contain a
n accessible parameterless constructor. (https://learn.microsoft.com/dotnet/fundamentals/syslib-diagnostics/syslib1220) [Q:\src\K8sTest\K8sTest.csproj]
Q:\src\K8sTest\Program.cs(9,24): warning SYSLIB1030: Did not generate serialization metadata for type 'k8s.Models.ResourceQuantity'. (https://learn.microsoft.com/dotnet/fundamentals/syslib-diagnostics/syslib1030) [Q:\src\K8sT
est\K8sTest.csproj]
Q:\src\K8sTest\Program.cs(9,24): warning SYSLIB1220: The 'JsonConverterAttribute' type 'k8s.Models.IntOrStringJsonConverter' specified on member 'k8s.Models.IntstrIntOrString' is not a converter type or does not contain an ac
cessible parameterless constructor. (https://learn.microsoft.com/dotnet/fundamentals/syslib-diagnostics/syslib1220) [Q:\src\K8sTest\K8sTest.csproj]
Q:\src\K8sTest\Program.cs(9,24): warning SYSLIB1030: Did not generate serialization metadata for type 'k8s.Models.IntstrIntOrString'. (https://learn.microsoft.com/dotnet/fundamentals/syslib-diagnostics/syslib1030) [Q:\src\K8s
Test\K8sTest.csproj]
Q:\src\K8sTest\System.Text.Json.SourceGeneration\System.Text.Json.SourceGeneration.JsonSourceGenerator\SourceGenerationContext.IDictionaryStringResourceQuantity.g.cs(54,84): error CS0103: The name 'ResourceQuantity' does not
exist in the current context [Q:\src\K8sTest\K8sTest.csproj]
The scenario I'm running into is that I'm including a V1Pod in another class I have for auditing/logging. Since I want to serialize my wrapper into json, I need to create a SourceGenerationContext for my own type. However, the source generation for that fails because it doesn't have access to the internal member IntOrStringJsonConverter. Here's a simplified example with a little more context.
// Example ClasspublicsealedclassAdmissionControllerAuditLog{publicboolAdmitted{get;init;}publicstringCreationSource{get;init;}publicV1PodTarget{get;init;}}[JsonSerializable(typeof(AdmissionControllerAuditLog))]internalpartialclassSourceGenerationContext:JsonSerializerContext{}
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.
Activity
peter-glotfelty commentedon Mar 4, 2024
A little more context here would be that for some code paths, we log the json dump of the object that we're applying to the cluster so this doesn't affect the Client itself per se but would be nice for some of the observability things we do.
So more generally, then I guess the ask is that either the appropriate converters + models are public, or that the associated source generator metadata can be made public enough for us to use them outside of the K8s Client itself
IvanJosipovic commentedon Mar 4, 2024
I fixed this in, #1311 but it was closed. I would also like this PR to be completed, as I would like the performance benefits but don't plan on using full AOT.
tg123 commentedon Mar 5, 2024
did you try Kubernetes.Aot?
tg123 commentedon Mar 24, 2024
@peter-glotfelty could you please try example?
https://github.com/kubernetes-client/csharp/tree/master/examples/aot
dotnet publish -r win-x64
@IvanJosipovic seesm too many warnings when introduce trimming to main sdk, not 100% if any bugs introduced by it
peter-glotfelty commentedon Mar 26, 2024
Hi @tg123, thank you for following up, I tried switching to the Aot lib and that doesn't make the error go away. Here's my
Program.cs.And the errors from dotnet publish -r win-x64
tg123 commentedon Mar 28, 2024
may i know why you have your own
SourceGenerationContextin code?here is the one in aot, you do not have to create a new
https://github.com/kubernetes-client/csharp/blob/master/src/KubernetesClient.Aot/SourceGenerationContext.cs
peter-glotfelty commentedon Apr 9, 2024
The scenario I'm running into is that I'm including a V1Pod in another class I have for auditing/logging. Since I want to serialize my wrapper into json, I need to create a SourceGenerationContext for my own type. However, the source generation for that fails because it doesn't have access to the internal member IntOrStringJsonConverter. Here's a simplified example with a little more context.
tg123 commentedon Apr 10, 2024
ah i see, this is by design at the moment.
but will support it later
IvanJosipovic commentedon Jun 19, 2024
I also need the converters to be public as I'm generating classes for CRDs. Due to this, the provided SourceGenerationContext is not sufficient.
k8s-triage-robot commentedon Sep 17, 2024
The Kubernetes project currently lacks enough contributors to adequately respond to all issues.
This bot triages un-triaged issues according to the following rules:
lifecycle/staleis appliedlifecycle/stalewas applied,lifecycle/rottenis appliedlifecycle/rottenwas applied, the issue is closedYou can:
/remove-lifecycle stale/closePlease send feedback to sig-contributor-experience at kubernetes/community.
/lifecycle stale
k8s-triage-robot commentedon Oct 17, 2024
The Kubernetes project currently lacks enough active contributors to adequately respond to all issues.
This bot triages un-triaged issues according to the following rules:
lifecycle/staleis appliedlifecycle/stalewas applied,lifecycle/rottenis appliedlifecycle/rottenwas applied, the issue is closedYou can:
/remove-lifecycle rotten/closePlease send feedback to sig-contributor-experience at kubernetes/community.
/lifecycle rotten
k8s-triage-robot commentedon Nov 16, 2024
The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs.
This bot triages issues according to the following rules:
lifecycle/staleis appliedlifecycle/stalewas applied,lifecycle/rottenis appliedlifecycle/rottenwas applied, the issue is closedYou can:
/reopen/remove-lifecycle rottenPlease send feedback to sig-contributor-experience at kubernetes/community.
/close not-planned
k8s-ci-robot commentedon Nov 16, 2024
@k8s-triage-robot: Closing this issue, marking it as "Not Planned".
Details
In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.