Skip to content

Make DependencyProvider test cleanup tolerant of missing registry subkey - #54936

Merged
Evangelink merged 1 commit into
mainfrom
evangelink-fix-dependencyprovider-test
Jun 23, 2026
Merged

Evangelink merged 1 commit into
mainfrom
evangelink-fix-dependencyprovider-test

Conversation

@Evangelink

@Evangelink Evangelink commented Jun 23, 2026 •

Copy link
Copy Markdown
Member

Problem

DependencyProviderTests.ItCanAddDependents (and the other registry-backed tests) could fail with:

System.ArgumentException: Cannot delete a subkey tree because the subkey does not exist.
   at Microsoft.Win32.RegistryKey.DeleteSubKeyTree(String subkey, Boolean throwOnMissingSubKey)
   at DependencyProviderTests.DeleteProviderKey(DependencyProvider dep)
   at DependencyProviderTests.ItCanAddDependents()

The DeleteProviderKey cleanup helper runs in a finally block. When an assertion inside the try fails before the provider key is created (or the key was already removed), DeleteSubKeyTree throws ArgumentException, which masks the real test failure.

Fix

Use the DeleteSubKeyTree(string subkey, bool throwOnMissingSubKey) overload with throwOnMissingSubKey: false so the cleanup is idempotent and never throws when the subkey is absent.

Fixes #54927

Co-authored-by: Copilot [email protected]

Copilot AI review requested due to automatic review settings June 23, 2026 07:38

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

Makes registry-backed DependencyProviderTests cleanup idempotent so test failures aren’t masked by a secondary cleanup exception when the provider subkey was never created (or was already removed).

Changes:

  • Switches registry cleanup to RegistryKey.DeleteSubKeyTree(subkey, throwOnMissingSubKey: false) so missing subkeys don’t throw during finally cleanup.
Show a summary per file
File Description
test/Microsoft.DotNet.Cli.Utils.Tests/DependencyProviderTests.cs Makes registry cleanup tolerant of missing provider subkey to avoid masking the real test failure.

Copilot's findings

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

@Evangelink
Evangelink enabled auto-merge June 23, 2026 07:43
@Evangelink

Copy link
Copy Markdown
Member Author

/ba-g #54928

@Evangelink
Evangelink merged commit c8e4965 into main Jun 23, 2026
25 of 27 checks passed
@Evangelink
Evangelink deleted the evangelink-fix-dependencyprovider-test branch June 23, 2026 09:36
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 11.0-preview6 milestone Jun 24, 2026
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.

System.ArgumentException: Cannot delete a subkey tree because the subkey does not exist

3 participants