Skip to content

Cleanup | Centralise AppContext switches #3492

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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

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).

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