Skip to content

Fix NRE in ToolConfigurationDeserializer when RuntimeIdentifierPackages is null - #53369

Merged
marcpopMSFT merged 1 commit into
release/10.0.3xxfrom
copilot/add-null-check-in-tool-config
Apr 17, 2026
Merged

Fix NRE in ToolConfigurationDeserializer when RuntimeIdentifierPackages is null#53369
marcpopMSFT merged 1 commit into
release/10.0.3xxfrom
copilot/add-null-check-in-tool-config

Conversation

CopilotAI commented Mar 10, 2026

Copy link
Copy Markdown
Contributor

When a tool's settings XML omits the <RuntimeIdentifierPackages> element, ridSpecificPackages is null (via ?.ToDictionary(...)), causing an unhandled NullReferenceException on the subsequent .Any() call rather than a clean error message.

Changes

  • ToolConfigurationDeserializer.cs: Guard .Any() call with an explicit null check on ridSpecificPackages:
    // Beforeif(string.IsNullOrEmpty(runner)&&!ridSpecificPackages.Any())// Afterif(string.IsNullOrEmpty(runner)&&(ridSpecificPackages==null||!ridSpecificPackages.Any()))
Original prompt

This section details on the original issue you should resolve

<issue_title>dotnet tool install crash with NRE in ToolConfigurationDeserializer</issue_title>
<issue_description>### Describe the bug

Was trying to debug why tool install fail with Unhandled exception: Value cannot be null. (Parameter 'source') error and found out that it fails here:

https://github.com/dotnet/sdk/blob/v10.0.103/src/Cli/dotnet/ToolPackage/ToolConfigurationDeserializer.cs#L70-L74

ridSpecificPackages is not checked for null

Exceptions (if any)

It would have saved time to debug it if exception stack were logged, not only exception messages.

.NET SDK:
Version: 10.0.103
Commit: c2435c3e0f
Workload version: 10.0.100-manifests.c992be6d
MSBuild version: 18.0.11+c2435c3e0
```</issue_description>
<agent_instructions>Add the null check even though we don't support this scenario.</agent_instructions>
## Comments on the Issue (you are @copilot in this section)
<comments>
<comment_new><author>@baronfel</author><body>
Obviously we should fix nullrefs, so we should fix this. But I have to say to be 100% clear that we definitely do not support custom-made tool settings xml files.</body></comment_new>
</comments>

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

CopilotAI changed the title [WIP] Fix null reference exception in ToolConfigurationDeserializerFix NRE in ToolConfigurationDeserializer when RuntimeIdentifierPackages is nullMar 10, 2026
@marcpopMSFT
marcpopMSFT marked this pull request as ready for review March 16, 2026 23:54
@marcpopMSFT

Copy link
Copy Markdown
Member

Code looks right. It should catch the null ref and provide this error now: "Tool '{0}' uses unsupported runner '{1}'."

CopilotAI 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

Fixes a crash in the .NET tool settings XML deserialization path when <RuntimeIdentifierPackages> is omitted and the tool command’s Runner is empty, ensuring a ToolConfigurationException is thrown instead of a NullReferenceException.

Changes:

  • Add a null-safe guard around the RID-specific packages .Any() check when Runner is empty.

Comment threadsrc/Cli/dotnet/ToolPackage/ToolConfigurationDeserializer.cs
Comment threadsrc/Cli/dotnet/ToolPackage/ToolConfigurationDeserializer.cs
…null
Co-authored-by: marcpopMSFT <12663534+marcpopMSFT@users.noreply.github.com>
@marcpopMSFT
marcpopMSFTforce-pushed the copilot/add-null-check-in-tool-config branch from e92386e to b055eddCompareApril 17, 2026 18:25
@marcpopMSFT
marcpopMSFT merged commit 17d3c7c into release/10.0.3xxApr 17, 2026
28 checks passed
@marcpopMSFT
marcpopMSFT deleted the copilot/add-null-check-in-tool-config branch April 17, 2026 21:57
Sign up for freeto 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.

4 participants

@marcpopMSFT@dsplaisted