Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@elinor-fung
Copy link
Member

@elinor-fung elinor-fung commented Oct 1, 2025

When getting the global.json state for telemetry, we avoid the work to actually resolve an SDK. However, this means that the actual SDK resolution (hostfxr_resolve_sdk2) fails, resulting in messages printed to stderr by default. This change uses hostfxr_set_error_writer to swallow the expected errors for the duration of that call and re-enables sending the telemetry for global.json state

cc @dotnet/appmodel @AaronRobinsonMSFT

Issue about writing to stderr in original implementation: #50632
Issue about adding this telemetry - resolves #50058

@dotnet/dotnet-cli I'd also like to get this in 10 if possible. What would be the process and correct branch to target?

Impact

This telemetry will give us information about the global.json state when an SDK command is invoked. We've gotten feedback over the years about how invalid global.json files shouldn't be ignored. This telemetry will give us a sense of how common this situation is and inform any decision to around changing the behaviour in a future release.

Regression

  • Yes
  • No

Risk

Low. This is fixing an issue in the original implementation where we'd end up printing extra/undesired messages when getting the information for telemetry. The fix is simply to swallow those messages.

@elinor-fung elinor-fung requested review from a team, baronfel and Copilot October 1, 2025 21:22
@github-actions
Copy link
Contributor

github-actions bot commented Oct 1, 2025

This PR is targeting main, which is now for .NET 11-facing work. If you intended to target .NET 10, either retarget this PR to release/10.0.1xx or make sure you backport the change to release/10.0.1xx after merging. See #50394 for more details.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR re-enables telemetry for global.json state while preventing unwanted error messages from appearing in stderr. The solution involves using hostfxr_set_error_writer to temporarily suppress expected SDK resolution errors during telemetry data collection.

  • Adds a new GetGlobalJsonState method that safely extracts global.json information without printing errors
  • Introduces native interop bindings for the hostfxr error writer functionality
  • Updates the telemetry collection code to use the new error-suppressed method

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
NETCoreSdkResolverNativeWrapper.cs Adds new GetGlobalJsonState method with error suppression
Interop.cs Adds native function bindings for hostfxr error writer
Program.cs Updates telemetry code to use new error-suppressed method

@baronfel
Copy link
Member

baronfel commented Oct 1, 2025

@elinor-fung for GA target the release/10.0.1xx branch please. Thanks for sending this :)

@elinor-fung elinor-fung force-pushed the globalJsonState-telemetry branch from bb0cc87 to 13a8022 Compare October 1, 2025 23:05
@elinor-fung elinor-fung requested review from a team and tmat as code owners October 1, 2025 23:05
@elinor-fung elinor-fung changed the base branch from main to release/10.0.1xx October 1, 2025 23:05
@elinor-fung elinor-fung removed request for a team and tmat October 1, 2025 23:06
@elinor-fung
Copy link
Member Author

Retargeted to release/10.0.1xx

Copy link
Member

@AaronRobinsonMSFT AaronRobinsonMSFT left a comment

Choose a reason for hiding this comment

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

LGTM :shipit:

@elinor-fung elinor-fung merged commit 8f5ca8f into dotnet:release/10.0.1xx Oct 2, 2025
27 checks passed
@elinor-fung elinor-fung deleted the globalJsonState-telemetry branch October 2, 2025 21:53
@baronfel
Copy link
Member

baronfel commented Oct 2, 2025

oh we should have Tactics-preflighted this. @elinor-fung can you send mail please?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants