Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Breaking change]: app.config cannot have a <section name="system.diagnostics" entry #32147

Closed
1 of 2 tasks
steveharter opened this issue Nov 2, 2022 · 4 comments · Fixed by #32171
Closed
1 of 2 tasks
Assignees
Labels
binary incompatible Existing binaries may encounter a breaking change in behavior. breaking-change Indicates a .NET Core breaking change 🏁 Release: .NET 7 Work items for the .NET 7 release

Comments

@steveharter
Copy link
Member

steveharter commented Nov 2, 2022

Description

For applications that have an app.config, the <configuration><configSection> entry may contain a <section name="system.diagnostics" entry which is no longer allowed. If present, the entry needs to be removed.

Having a <section name="system.diagnostics" entry causes the following exception the first time the configuration system is used:
ConfigurationErrorsException: Section or group name 'system.diagnostics' is already defined. Updates to this may only occur at the configuration level where it is defined.

For example, this app.config file:

<configuration>
 <configSections>
   <section name="system.diagnostics"
            type="System.Diagnostics.SystemDiagnosticsSection,
            System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
 </configSections>  

contains the unnecessary entry.

Feature area: System.Configuration (app.config files)

Version

.NET 7 RC 1

Previous behavior

Specifying <section name="system.diagnostics" was allowed and necessary if there was a later system.diagnostics configuration section like:

<configuration>
    <system.diagnostics>

However, System.Diagnostics did not yet support the feature that processes that section in order to add various listeners and other control other diagnostic features, so it was not automatically read. Only applications which had a<system.diagnostics> section would require a <section name="system.diagnostics" entry.

.NET Framework, however, does support processing of the "system.diagnostics" section and had an <section name="system.diagnostics" in the machine.config file.

Thus, this issue likely only occurs for:

  • Applications that were using .NET Framework and migrated to .NET.
  • Manually added <section name="system.diagnostics" to the app.config to support manual reading of the <system.diagnostics> section.
  • Upgraded to 7.0 which now has an implicit <section name="system.diagnostics" entry.

New behavior

System.Diagnostics now supports reading the <system.diagnostics> section from the config file and added an implicit <section name="system.diagnostics" entry. Having an explicit <section name="system.diagnostics" entry in the app.config file causes a duplicate which throws ConfigurationErrorsException.

Type of breaking change

  • Binary incompatible: Existing binaries may encounter a breaking change in behavior, such as failure to load/execute or different run-time behavior.
  • Source incompatible: Source code may encounter a breaking change in behavior when targeting the new runtime/component/SDK, such as compile errors or different run-time behavior.

Reason for change

The implementation to support the feature where System.Diagnostics reads from the app.config required adding the implicit <section name="system.diagnostics" element. See dotnet/runtime#23937 for details on the feature request.

Recommended action

The unnecessary <section name="system.diagnostics" entry should be removed.

Feature area

Other (please put exact area in description textbox)

Affected APIs

No response

@RussKie
Copy link
Member

RussKie commented Nov 2, 2022

Is TraceConfiguration.Register() required to be added to the user's code?

@steveharter
Copy link
Member Author

Is TraceConfiguration.Register() required to be added to the user's code?

No, the exception occurs the first time the configuration system is used. So, for example, just this will cause the exception:

int value = Int32.Parse(ConfigurationManager.AppSettings["some setting"]);

@steveharter
Copy link
Member Author

Note that I need to update the description here to remove the .NET Framework references since that was not correct -- .NET Framework had a machine.config file with the diagnostics section and did not force the entry in the app.config.

@steveharter
Copy link
Member Author

(description updated; ready for review)

@ghost ghost added the in-pr This issue will be closed (fixed) by an active pull request. label Nov 3, 2022
@gewarren gewarren moved this from 🔖 Ready to 🏗 In progress in dotnet/docs November Sprint Nov 3, 2022
Repository owner moved this from 🏗 In progress to ✅ Done in dotnet/docs November Sprint Nov 7, 2022
@ghost ghost removed the in-pr This issue will be closed (fixed) by an active pull request. label Nov 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
binary incompatible Existing binaries may encounter a breaking change in behavior. breaking-change Indicates a .NET Core breaking change 🏁 Release: .NET 7 Work items for the .NET 7 release
Projects
No open projects
Status: Done
Status: Done
Development

Successfully merging a pull request may close this issue.

4 participants