Open
Description
What should we add or change to make your life better?
Address all trimming and AOT warnings in Yarp.Kubernetes.Controller.
The current warnings are from 2 API usages:
- Using System.Text.Json Serialization
- Using ConfigurationBinder
Both of these APIs use unbounded runtime Reflection. There are 2 general approaches to resolving these warnings:
- Use the Source Generators for each. Note that the ConfigurationBinder source generator is new in .NET 8 - Developers can safely trim apps which need Configuration Binder runtime#44493.
- Manually writing the code the source generator/Reflection is doing. For example, using Utf8JsonReader/Writer.
I would suggest using the Source Generators.
Note that using the JSON Source Generator right now isn't possible because of dotnet/runtime#79311. We need this functionality to serialize a Message
:
So we will have to wait until that bug is fixed.
Here are the current warnings from this project:
1>C:\git\reverse-proxy\src\Kubernetes.Controller\Services\Reconciler.cs(62,36,62,82): warning IL3050: Using member 'System.Text.Json.JsonSerializer.Serialize<TValue>(TValue, JsonSerializerOptions)' which has 'RequiresDynamicCodeAttribute' can break functionality when AOT compiling. JSON serialization and deserialization might require types that cannot be statically analyzed and might need runtime code generation. Use System.Text.Json source generation for native AOT applications.
1>C:\git\reverse-proxy\src\Kubernetes.Controller\Services\Reconciler.cs(63,36,63,70): warning IL3050: Using member 'System.Text.Json.JsonSerializer.Serialize<TValue>(TValue, JsonSerializerOptions)' which has 'RequiresDynamicCodeAttribute' can break functionality when AOT compiling. JSON serialization and deserialization might require types that cannot be statically analyzed and might need runtime code generation. Use System.Text.Json source generation for native AOT applications.
1>C:\git\reverse-proxy\src\Kubernetes.Controller\Services\Reconciler.cs(62,36,62,82): warning IL2026: Using member 'System.Text.Json.JsonSerializer.Serialize<TValue>(TValue, JsonSerializerOptions)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.
1>C:\git\reverse-proxy\src\Kubernetes.Controller\Services\Reconciler.cs(63,36,63,70): warning IL2026: Using member 'System.Text.Json.JsonSerializer.Serialize<TValue>(TValue, JsonSerializerOptions)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.
1>C:\git\reverse-proxy\src\Kubernetes.Controller\Protocol\DispatchConfigProvider.cs(33,21,33,65): warning IL3050: Using member 'System.Text.Json.JsonSerializer.SerializeToUtf8Bytes<TValue>(TValue, JsonSerializerOptions)' which has 'RequiresDynamicCodeAttribute' can break functionality when AOT compiling. JSON serialization and deserialization might require types that cannot be statically analyzed and might need runtime code generation. Use System.Text.Json source generation for native AOT applications.
1>C:\git\reverse-proxy\src\Kubernetes.Controller\Protocol\DispatchConfigProvider.cs(33,21,33,65): warning IL2026: Using member 'System.Text.Json.JsonSerializer.SerializeToUtf8Bytes<TValue>(TValue, JsonSerializerOptions)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.
1>C:\git\reverse-proxy\src\Kubernetes.Controller\Management\KubernetesReverseProxyServiceCollectionExtensions.cs(83,9,83,67): warning IL3050: Using member 'Microsoft.Extensions.DependencyInjection.OptionsConfigurationServiceCollectionExtensions.Configure<TOptions>(IServiceCollection, IConfiguration)' which has 'RequiresDynamicCodeAttribute' can break functionality when AOT compiling. Binding strongly typed objects to configuration values may require generating dynamic code at runtime.
1>C:\git\reverse-proxy\src\Kubernetes.Controller\Management\KubernetesReverseProxyServiceCollectionExtensions.cs(83,9,83,67): warning IL2026: Using member 'Microsoft.Extensions.DependencyInjection.OptionsConfigurationServiceCollectionExtensions.Configure<TOptions>(IServiceCollection, IConfiguration)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. TOptions's dependent types may have their members trimmed. Ensure all required members are preserved.
1>C:\git\reverse-proxy\src\Kubernetes.Controller\Protocol\DispatchActionResult.cs(57,29,60,15): warning IL3050: Using member 'System.Text.Json.JsonSerializer.SerializeToUtf8Bytes<TValue>(TValue, JsonSerializerOptions)' which has 'RequiresDynamicCodeAttribute' can break functionality when AOT compiling. JSON serialization and deserialization might require types that cannot be statically analyzed and might need runtime code generation. Use System.Text.Json source generation for native AOT applications.
1>C:\git\reverse-proxy\src\Kubernetes.Controller\Protocol\DispatchActionResult.cs(57,29,60,15): warning IL2026: Using member 'System.Text.Json.JsonSerializer.SerializeToUtf8Bytes<TValue>(TValue, JsonSerializerOptions)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.
1>C:\git\reverse-proxy\src\Kubernetes.Controller\Protocol\Receiver.cs(75,35,75,93): warning IL3050: Using member 'System.Text.Json.JsonSerializer.Deserialize<TValue>(String, JsonSerializerOptions)' which has 'RequiresDynamicCodeAttribute' can break functionality when AOT compiling. JSON serialization and deserialization might require types that cannot be statically analyzed and might need runtime code generation. Use System.Text.Json source generation for native AOT applications.
1>C:\git\reverse-proxy\src\Kubernetes.Controller\Protocol\Receiver.cs(75,35,75,93): warning IL2026: Using member 'System.Text.Json.JsonSerializer.Deserialize<TValue>(String, JsonSerializerOptions)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.
Why is this important to you?
This allows Yarp.Kubernetes.Controller to be used in a Native AOT app, which has smaller disk footprint, faster start up, and less memory consumption.