Skip to content

Don't retain host probing-path properties in CLR config and AppContext#129995

Open
elinor-fung wants to merge 5 commits into
dotnet:mainfrom
elinor-fung:skip-storing-known-host-prop
Open

Don't retain host probing-path properties in CLR config and AppContext#129995
elinor-fung wants to merge 5 commits into
dotnet:mainfrom
elinor-fung:skip-storing-known-host-prop

Conversation

@elinor-fung

@elinor-fung elinor-fung commented Jun 29, 2026

Copy link
Copy Markdown
Member

Four well-known host probing-path properties — TRUSTED_PLATFORM_ASSEMBLIES, NATIVE_DLL_SEARCH_DIRECTORIES, PLATFORM_RESOURCE_ROOTS, and APP_PATHS — are computed by the host and then, inside the runtime, copied and retained multiple times: wide-string copies in the CLR config knobs, managed strings in AppContext's data store, and the parsed binder/AppDomain structures the runtime actually uses. The config-knob and AppContext copies just duplicate data the runtime already owns in parsed form. The TPA list is the largest of these and grows as the app takes dependencies on other libraries or frameworks.

This change stops keeping the copies in the config knobs and managed AppContext. The host properties are still handed to the runtime and parsed by the binder and AppDomain, but the config knob copies for these four properties are dropped and they are no longer stored on the AppContext at startup. When one of these properties is requested through AppContext.GetData, the value is reconstructed from the binder/AppDomain state via a new QCall and stored for subsequent reads. Reconstruction is not byte-for-byte: the TPA list comes back deduplicated by simple name and in a different order, and a property the host passed as empty reads back as null rather than an empty string.

cc @dotnet/appmodel @AaronRobinsonMSFT

Note

Portions of this PR description were drafted with the assistance of GitHub Copilot.

elinor-fung and others added 3 commits June 25, 2026 13:31
In coreclr_initialize, the wide-string copies of all host properties
were stored in the CLR config knobs and held forever. For probing-path
properties (TRUSTED_PLATFORM_ASSEMBLIES, NATIVE_DLL_SEARCH_DIRECTORIES,
PLATFORM_RESOURCE_ROOTS, APP_PATHS) these duplicate data the runtime
already owns: the binder/AppDomain parses them into its own structures
during CreateAppDomainWithManager, and the managed AppContext.Setup
copies each value into a managed string. The TPA list in particular can
be tens of KB.

Build a filtered property array for Configuration::InitializeConfigurationKnobs
that excludes those four properties, and free their wide-string copies
after CreateAppDomainWithManager has consumed them.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Extend the host-property elision so the probing-path properties
(TRUSTED_PLATFORM_ASSEMBLIES, NATIVE_DLL_SEARCH_DIRECTORIES,
PLATFORM_RESOURCE_ROOTS, APP_PATHS) are not stored in managed
AppContext.s_dataStore either. The runtime already owns the parsed
forms (binder's TPA map, AppDomain's native search dirs, etc.), so
the managed string copy is redundant.

AppContext.GetData transparently reconstructs the value on first
access via a new QCall (AppContext_TryGetHostPropertyValue) and caches
the result for subsequent calls. The QCall returns TRUE when the
property has data in the binder/AppDomain state, FALSE otherwise -
GetData returns null in the latter case, matching the previous
behavior of returning null for properties the host did not pass.

The Mono and NativeAOT code paths are unchanged.

Saves the managed string allocation for each of these properties
(~26 KB for TPA in a typical framework).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Verify that AppContext.GetData can retrieve the four known host
probing-path properties (TRUSTED_PLATFORM_ASSEMBLIES,
NATIVE_DLL_SEARCH_DIRECTORIES, PLATFORM_RESOURCE_ROOTS, APP_PATHS)
which are reconstructed on demand from binder/AppDomain state rather
than stored in AppContext.s_dataStore.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @agocke
See info in area-owners.md if you want to be subscribed.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Reduces retained memory for large host-provided probing path properties by no longer storing them permanently in CLR config knobs or AppContext’s managed data store, instead reconstructing them on demand from binder/AppDomain state.

Changes:

  • Stop storing known host probing-path properties in AppContext.Setup, and lazily reconstruct them on AppContext.GetData via a new QCall.
  • Filter out host probing-path properties when initializing CLR configuration knobs, and free the excluded wide-string copies after AppDomain creation.
  • Add/adjust HostActivation tests to validate AppContext.GetData access for known host properties.
Show a summary per file
File Description
src/libraries/System.Private.CoreLib/src/System/AppContext.cs Skips storing known host probing-path properties at setup; lazily retrieves and caches them when requested via GetData.
src/coreclr/System.Private.CoreLib/src/System/AppContext.CoreCLR.cs Adds host-property identification and a QCall import used to reconstruct values on demand.
src/coreclr/vm/qcallentrypoints.cpp Registers the new QCall entrypoint.
src/coreclr/vm/appdomainnative.hpp Declares the new QCall entrypoint signature.
src/coreclr/vm/appdomainnative.cpp Implements QCall to reconstruct host property values from binder/AppDomain state.
src/coreclr/dlls/mscoree/exports.cpp Filters known host probing-path properties out of CLR config knob storage and frees excluded wide-string copies post-AppDomain creation.
src/installer/tests/HostActivation.Tests/RuntimeProperties.cs Updates assertions and adds coverage for retrieving known host properties via AppContext.GetData.

Copilot's findings

  • Files reviewed: 7/7 changed files
  • Comments generated: 1

Comment thread src/coreclr/dlls/mscoree/exports.cpp
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings June 29, 2026 20:31

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot's findings

  • Files reviewed: 7/7 changed files
  • Comments generated: 2

Comment thread src/libraries/System.Private.CoreLib/src/System/AppContext.cs
Comment thread src/coreclr/dlls/mscoree/exports.cpp
Copilot AI review requested due to automatic review settings June 29, 2026 21:35

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot's findings

  • Files reviewed: 7/7 changed files
  • Comments generated: 2

Comment thread src/coreclr/System.Private.CoreLib/src/System/AppContext.CoreCLR.cs
Comment thread src/installer/tests/HostActivation.Tests/RuntimeProperties.cs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

2 participants