dotnet / runtime

.NET is a cross-platform runtime for cloud, mobile, desktop, and IoT apps.
https://docs.microsoft.com/dotnet/core/
MIT License
15.3k stars 4.74k forks source link

Correct Trimming RootMode for ConfigurationManager #109777

Closed Trimatix closed 16 hours ago

Trimatix commented 20 hours ago

Hi there, this is a followup after #101423.

I've rooted ConfigurationManager as described using TrimmerRootAssembly, but dotnet publish says that ConfigurationManager does not specify a RootMode, so I've given <TrimmerRootAssembly Include="System.Configuration.ConfigurationManager" RootMode="Library" />.

In this mode, I still get the Unhandled exception. System.Configuration.ConfigurationErrorsException: Configuration system failed to initialize error from #101423.

Please could you advise the correct rootmode to use for this package? I haven't been able to find the documentation for RootMode online as of yet.

Many thanks in advance

(dotnet 8, linux-x64)

dotnet-policy-service[bot] commented 20 hours ago

Tagging subscribers to this area: @dotnet/area-system-configuration See info in area-owners.md if you want to be subscribed.

jkotas commented 17 hours ago

System.Configuration.ConfigurationManager design is incompatible with trimming. It is not possible to make it work well in trimmed applications.

You may want to consider switching to a configuration library that is compatible with trimming such as https://learn.microsoft.com/en-us/dotnet/core/whats-new/dotnet-8/runtime#configuration-binding-source-generator . (This is documented at https://learn.microsoft.com/en-us/dotnet/core/deploying/trimming/incompatibilities#reflection-based-serializers .)

steveharter commented 16 hours ago

System.Configuration.ConfigurationManager design is incompatible with trimming. It is not possible to make it work well in trimmed applications.

Closing;

There is some work in v10 on this: https://github.com/dotnet/runtime/pull/108464

sbomer commented 13 hours ago

Just FYI, the work in https://github.com/dotnet/runtime/pull/108464 is designed to provide better trim warnings when using ConfigurationManager - not to make it compatible with trimming.

Trimatix commented 4 hours ago

understood, thanks all 👍