LaunchDarkly.ClientSDK 5.3.0 fails in trimmed applications · Issue #90 · launchdarkly/dotnet-core · GitHub
More Web Proxy on the site http://driver.im/
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
Describe the bug
If I create a trimmed application the SDK fails due to the use of reflection based JSON serialisation.
To reproduce
Create a new .NET project and enable trimming in the project file.
true
Integrate the LaunchDarkly API as per your sample applications, when LDClient.Init() is called the following exception will be raised.
2025-04-04 11:22:48.981 +11:00 [LaunchDarkly.Sdk] INFO: Starting LaunchDarkly Client 5.3.0.0 built with target framework net7.0
2025-04-04 11:22:49.034 +11:00 [LaunchDarkly.Sdk] INFO: Network availability is now True
Unhandled exception. System.InvalidOperationException: Reflection-based serialization has been disabled for this application. Either use the source generator APIs or explicitly configure the 'JsonSerializerOptions.TypeInfoResolver' property.
at LaunchDarkly.Sdk.Internal.Concurrent.AsyncUtils.WaitSafely(Func`1 taskFn, TimeSpan timeout)
at LaunchDarkly.Sdk.Client.LdClient.Start(TimeSpan maxWaitTime)
at LaunchDarkly.Sdk.Client.LdClient.Init(Configuration config, Context initialContext, TimeSpan maxWaitTime)
at Program.
$(String[] args) in /Users/ghughes/Developer/CurlAgents/LaunchDarkly/Program.cs:line 6
Expected behavior
The LDClient.Init() method returns without throwing this exception.
Logs
See above.
SDK version
Client 5.3.0
Language version, developer tools
.NET 8.0.
OS/platform
Tested on macOS but exception is not platform specific.
The text was updated successfully, but these errors were encountered:
Hi @GaryHughes. We see this sometimes in other ecosystems that use reflection around the communication protocol. Is there a way for you to disable trimming for a subset of packages/classes? That may be faster and more guaranteed to get you unblocked. I am not familiar with the flexibility of the trimming configuration for .NET.
Hi @tanderson-ld disabling trimming in general is not possible, our software has tight size constraints that preclude this. I'll look at the options for excluding your code but our experience with that technique has not been great. Replacing reflection based serialisation with source generators is quite straight forward, there is a good explainer here if you haven't seen it https://learn.microsoft.com/en-us/dotnet/standard/serialization/system-text-json/source-generation.
Describe the bug
If I create a trimmed application the SDK fails due to the use of reflection based JSON serialisation.
To reproduce
Create a new .NET project and enable trimming in the project file.
true
Integrate the LaunchDarkly API as per your sample applications, when LDClient.Init() is called the following exception will be raised.
2025-04-04 11:22:48.981 +11:00 [LaunchDarkly.Sdk] INFO: Starting LaunchDarkly Client 5.3.0.0 built with target framework net7.0
$(String[] args) in /Users/ghughes/Developer/CurlAgents/LaunchDarkly/Program.cs:line 62025-04-04 11:22:49.034 +11:00 [LaunchDarkly.Sdk] INFO: Network availability is now True
Unhandled exception. System.InvalidOperationException: Reflection-based serialization has been disabled for this application. Either use the source generator APIs or explicitly configure the 'JsonSerializerOptions.TypeInfoResolver' property.
at LaunchDarkly.Sdk.Internal.Concurrent.AsyncUtils.WaitSafely(Func`1 taskFn, TimeSpan timeout)
at LaunchDarkly.Sdk.Client.LdClient.Start(TimeSpan maxWaitTime)
at LaunchDarkly.Sdk.Client.LdClient.Init(Configuration config, Context initialContext, TimeSpan maxWaitTime)
at Program.
Expected behavior
The LDClient.Init() method returns without throwing this exception.
Logs
See above.
SDK version
Client 5.3.0
Language version, developer tools
.NET 8.0.
OS/platform
Tested on macOS but exception is not platform specific.
The text was updated successfully, but these errors were encountered: