Skip to content

Fixing reading of multiple app context switches from a single AppContextSwitchOverrides configuration field.#3960

Open
tetolv wants to merge 1 commit intodotnet:mainfrom
tetolv:AppContextSwitchOverrides_fix
Open

Fixing reading of multiple app context switches from a single AppContextSwitchOverrides configuration field.#3960
tetolv wants to merge 1 commit intodotnet:mainfrom
tetolv:AppContextSwitchOverrides_fix

Conversation

@tetolv
Copy link

@tetolv tetolv commented Feb 12, 2026

Description

SqlAppContextSwitchManager was unable to correctly parse multiple switches from the single configuration field. In case of such sample configuration:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <configSections>
    <section type="Microsoft.Data.SqlClient.AppContextSwitchOverridesSection, Microsoft.Data.SqlClient" name="AppContextSwitchOverrides"/>
  </configSections>
  <AppContextSwitchOverrides value="Switch.Microsoft.Data.SqlClient.EnableUserAgent=true;Switch.Microsoft.Data.SqlClient.UseCompatibilityProcessSni=true;System.Globalization.Invariant=false;"/>
</configuration>

following parsing code :

            string[] switches = appContextSwitches.Value?.Split('=', ';');
            ...
            for (int i = 0; i < switches.Length / 2; i++)
            {
                try
                {
                    AppContext.SetSwitch(switches[i], Convert.ToBoolean(switches[i + 1]));
                    SqlClientEventSource.Log.TryTraceEvent("<sc.{0}.{1}|INFO> Successfully assigned the AppContext switch '{2}'={3}.",
                                                           TypeName, methodName, switches[i], switches[i + 1]);
                }
                ...
            }

, on the second iteration would confuse switch key with a value and would try to convert key name to bool, which would of course fail.

One additional fix is for proper handling of configuration field, if it's content (sequence of switch=value pairs) starts, or ends with semicolon.

Testing

Changes seems trivial, bet unittests could be added, if deemed necessary.

@tetolv tetolv marked this pull request as ready for review February 13, 2026 16:38
@tetolv tetolv requested a review from a team as a code owner February 13, 2026 16:38
@paulmedynski
Copy link
Contributor

/azp run

@paulmedynski paulmedynski self-assigned this Feb 17, 2026
@azure-pipelines
Copy link

Azure Pipelines successfully started running 2 pipeline(s).

Copy link
Contributor

@paulmedynski paulmedynski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great catch! We clearly lack any unit tests for this, so I'll add that to the pile.

@codecov
Copy link

codecov bot commented Feb 17, 2026

Codecov Report

❌ Patch coverage is 0% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 67.69%. Comparing base (f06e783) to head (bf3de46).
⚠️ Report is 4 commits behind head on main.

Files with missing lines Patch % Lines
...ta/SqlClient/SqlAppContextSwitchManager.netcore.cs 0.00% 2 Missing ⚠️

❗ There is a different number of reports uploaded between BASE (f06e783) and HEAD (bf3de46). Click for more details.

HEAD has 1 upload less than BASE
Flag BASE (f06e783) HEAD (bf3de46)
addons 1 0
Additional details and impacted files
@@             Coverage Diff             @@
##             main    #3960       +/-   ##
===========================================
- Coverage   90.82%   67.69%   -23.14%     
===========================================
  Files           6      260      +254     
  Lines         316    65724    +65408     
===========================================
+ Hits          287    44490    +44203     
- Misses         29    21234    +21205     
Flag Coverage Δ
addons ?
netcore 67.85% <0.00%> (?)
netfx 66.44% <ø> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@paulmedynski paulmedynski requested a review from a team February 17, 2026 18:18
@paulmedynski paulmedynski added this to the 7.0.0-preview4 milestone Feb 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Comments