Fix debug assert in Uri.CreateThisFromUri when combining UNC base with "file:" relative URI#124660
Merged
Fix debug assert in Uri.CreateThisFromUri when combining UNC base with "file:" relative URI#124660
Conversation
Contributor
|
Tagging subscribers to this area: @karelz, @dotnet/ncl |
…nstructor flag Co-authored-by: MihaZupan <25307628+MihaZupan@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix debug assert in Uri's constructor handling
Fix debug assert in Uri.CreateThisFromUri when combining UNC base with "file:" relative URI
Feb 20, 2026
This was referenced Feb 20, 2026
MihaZupan
approved these changes
Feb 21, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a debug assertion failure in Uri.CreateThisFromUri when combining a UNC file URI base with a "file:" relative URI. The root cause was that CreateThisFromUri was copying all flags verbatim from the source URI, including the Debug_LeftConstructor flag, which is per-instance state that should only be set when the current constructor finishes.
Changes:
- Strip
Debug_LeftConstructorflag when copying flags inCreateThisFromUrito prevent re-entrant constructor calls from triggering false assertions - Add regression test covering the UNC +
"file:"relative URI combination scenario
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/libraries/System.Private.Uri/src/System/UriExt.cs | Strip Debug_LeftConstructor flag when copying flags from source URI in CreateThisFromUri method |
| src/libraries/System.Private.Uri/tests/FunctionalTests/UncTest.cs | Add regression test verifying that combining UNC base URI with "file:" relative URI does not trigger debug assertion |
rokonec
approved these changes
Feb 24, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Uri(Uri, Uri)triggers aDebug.Assertfailure inCreateThisFromUriwhen combining a UNC file URI base with a"file:"relative URI:Description
Root cause:
CreateThisFromUricopies all flags fromotherUriverbatim, includingDebug_LeftConstructor. InUri(Uri, Uri),CreateThisFromUriis called twice — first to initialize fromrelUri, and again afterResolveHelperreturns a resolved URI. On the second call,this._flagsalready carriesDebug_LeftConstructor(copied from the first call), soDebugAssertInCtor()fires.Fix: Strip
Debug_LeftConstructorfrom the copied flags inCreateThisFromUri:Debug_LeftConstructoris per-instance state — it must only be set viaDebugSetLeftCtor()when the current constructor finishes, never inherited from another URI.A regression test covering the UNC +
"file:"relative combination is added toUncTest.cs.Original prompt
🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.