Skip to content

Conversation

edwardneal
Copy link
Contributor

Description

We try to centralise all access to SqlClient's AppContext switches via the LocalAppContextSwitches class. There are currently a few cases where we don't do this though:

  • netcore's globalization invariant mode detection lives in SqlConnection
  • Switch.Microsoft.Data.SqlClient.TruncateScaledDecimal is handled by TdsParser on both targets
  • Switch.Microsoft.Data.SqlClient.UseManagedNetworkingOnWindows is handled by TdsParserStateObjectFactory

The first port of call is to relocate all of these to the existing LocalAppContextSwitches class. This slightly helps in the merge of SqlConnection.

I've also added an ILLink.Substitutions.xml resource to the output. This is a trimming improvement, and is documented here. It allows referencing applications to specify a RuntimeHostConfigurationOption to set an AppContext switch, which the IL trimmer will reference and remove the entire managed or native SNI. There's a little more work to come on this once trimming is ready.

For comparison purposes, this is modelled in part on CsWinRT:

I've used sizoscope to verify that I can use RuntimeHostConfigurationOption, publish an application and see the corresponding SNI's types are removed from the output.

Issues

Partially relates to #1261 and #1942.

Testing

Unit tests pass locally.

@edwardneal edwardneal requested a review from a team as a code owner July 19, 2025 10:30
@paulmedynski
Copy link
Contributor

/azp run

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.

Looks good, but need to also update this test helper:

src/Microsoft.Data.SqlClient/tests/Common/LocalAppContextSwitchesHelper.cs

@apoorvdeshmukh apoorvdeshmukh requested a review from a team July 22, 2025 17:11
Move string constants and variables together; add a comment to UseManagedNetworking explaining that it can be turned into a constant by ILLink.
These tests no longer directly set the AppContext switches to round or truncate decimals, since these switches are cached when first queried.
@edwardneal
Copy link
Contributor Author

edwardneal commented Jul 23, 2025

Thanks both. I've added the review comments, and the failing TestScaledDecimalParameter_* tests should now run correctly (as should the AdjustPrecScaleForBulkCopy test.) There are no other references to the AppContext switches in the tests as far as I can see.

Could you run CI please?

@mdaigle
Copy link
Contributor

mdaigle commented Jul 23, 2025

/azp run

Copy link

Azure Pipelines successfully started running 2 pipeline(s).

Copy link

codecov bot commented Jul 24, 2025

Codecov Report

Attention: Patch coverage is 76.92308% with 12 lines in your changes missing coverage. Please review.

Project coverage is 63.86%. Comparing base (42146a3) to head (880396a).
Report is 14 commits behind head on main.

Files with missing lines Patch % Lines
...icrosoft/Data/SqlClient/LocalAppContextSwitches.cs 74.19% 8 Missing ⚠️
...nt/netfx/src/Microsoft/Data/SqlClient/TdsParser.cs 0.00% 2 Missing ⚠️
...core/src/Microsoft/Data/SqlClient/SqlConnection.cs 50.00% 1 Missing ⚠️
.../netcore/src/Microsoft/Data/SqlClient/TdsParser.cs 80.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3492      +/-   ##
==========================================
- Coverage   68.85%   63.86%   -5.00%     
==========================================
  Files         277      270       -7     
  Lines       62237    61872     -365     
==========================================
- Hits        42854    39515    -3339     
- Misses      19383    22357    +2974     
Flag Coverage Δ
addons ?
netcore 67.17% <80.00%> (-5.51%) ⬇️
netfx 63.67% <69.23%> (-4.52%) ⬇️

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 merged commit e6428d6 into dotnet:main Jul 24, 2025
237 checks passed
@edwardneal edwardneal deleted the cleanup/appcontextswitches branch July 24, 2025 12:08
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.

3 participants