Skip to content

Harmless debug assert hit in Uri's DebugAssertInCtor #124659

Description

@MihaZupan
// Uri.CreateThisFromUri fires Debug.Assert: (_flags & Flags.Debug_LeftConstructor) == 0
// when combining a UNC file URI base with a "file:" relative URI.
//
// Source: System.Uri.DebugAssertInCtor() at Uri.cs:205
//         System.Uri.CreateThisFromUri() at UriExt.cs:891

var baseUri = new Uri(@"\\aa", UriKind.Absolute);   // parses as file://aa/
var relUri = new Uri("file:", UriKind.Relative);
_ = new Uri(baseUri, relUri);                        // Debug.Assert failure

The assert violation is in CreateThisFromUri — it expects the constructor flag Debug_LeftConstructor to not be set, but the re-entrant URI construction from a UNC base + file: relative violates this invariant.

This is from the extra DebugAssertInCtor I added to DebugSetLeftCtor in #123932. We should either remove the assert or avoid copying the Debug_LeftConstructor flag in CreateThisFromUri.

Activity

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

Metadata

Metadata

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions