Skip to content

Conversation

elinor-fung
Copy link
Member

@elinor-fung elinor-fung commented Aug 5, 2025

We currently ignore invalid global.json, which can lead to unexpected/undesired behaviour. While we're not going to change that behaviour right now, this change adds some indication about this situation in dotnet --info and updates a hostfxr API to indicate if an invalid global.json was found.

  • Make sdk_resolver track/store information about global.json even when it is deemed invalid
  • Update dotnet --info to list invalid global.json file path and error message
  • Add hostfxr_resolve_sdk2_result_key_t::global_json_state for hostfxr_resolve_sdk2 API
    • string values of: not_found, valid, invalid_json, invalid_data
    • This can be used in the SDK to add telemetry for when we have invalid global.json

Example part of dotnet --info:

global.json file:
  Invalid [C:\repos\helloworld\global.json]
    Version '9.0' is not valid for the 'sdk/version' value
    Invalid global.json is ignored for SDK resolution.

Before:

global.json file:
  Not found

cc @dotnet/appmodel @AaronRobinsonMSFT @richlander

Resolves #94496

Related:

@Copilot Copilot AI review requested due to automatic review settings August 5, 2025 22:42
Copy link
Contributor

@Copilot 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 enhances global.json error reporting in dotnet --info and the hostfxr_resolve_sdk2 API by tracking and exposing information about invalid global.json files instead of silently ignoring them.

  • Tracks global.json state (not_found, valid, invalid_json, invalid_data) throughout the SDK resolution process
  • Updates error reporting to provide specific error messages for JSON parsing and validation failures
  • Adds new global_json_state result key to hostfxr_resolve_sdk2 API for telemetry purposes

Reviewed Changes

Copilot reviewed 19 out of 19 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
src/native/corehost/json_parser.h Added get_error_message() method and m_parse_error field to store parsing errors
src/native/corehost/json_parser.cpp Modified to store error messages instead of immediately tracing them
src/native/corehost/hostmisc/utils.h Added format_string utility function for creating formatted strings
src/native/corehost/hostmisc/pal.h Added template str_printf and strlen_printf functions for cross-platform string formatting
src/native/corehost/fxr/sdk_resolver.h Restructured to track global.json state and error information in global_file_info struct
src/native/corehost/fxr/sdk_resolver.cpp Refactored global.json parsing to return state information and detailed error messages
src/native/corehost/fxr/hostfxr.cpp Added global_json_state result key and corresponding state strings for the API
src/native/corehost/fxr/command_line.cpp Updated dotnet --info to display invalid global.json information with error details
src/native/corehost/runtime_config.cpp Added error tracing using the new error message functionality
src/native/corehost/hostpolicy/deps_format.cpp Added error tracing for dependency JSON parsing failures
src/native/corehost/comhost/clsidmap.cpp Updated error messages to use the new error message functionality
Test files Updated test expectations to match new error message formats and added tests for invalid global.json scenarios

@elinor-fung elinor-fung merged commit 1a8ccb6 into dotnet:main Aug 14, 2025
143 of 146 checks passed
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

dotnet --info should indicate invalid global.json
3 participants