You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Object reference not set to an instance of an object.
+ System.Uri.CreateUriInfo(System.Uri.Flags)
+ System.Uri.EnsureUriInfo()
+ System.Uri.ParseRemaining()
+ System.Uri.EnsureParseRemaining()
+ System.Uri.CreateThis(string, bool, System.UriKind)
+ System.Uri.CreateUri(System.Uri, string, bool)
The exception type is unexpected, I would expect a UriFormatException to be thrown.
Changing : to %3a works fine
Changing %c3%b6 to a yields a better exception: System.UriFormatException: Invalid URI: The Authority/Host could not be parsed.
So there seems to be something going on with the UTF-8 decoding combined with special case when a protocol is at start of the string.
(The problem is the same under mono 5.4.1.6 on macOS)
Unhandled Exception: System.UriFormatException: Invalid URI: The Authority/Host could not be parsed.
at System.Uri.CreateThis(String uri, Boolean dontEscape, UriKind uriKind)
at System.Uri.CreateUri(Uri baseUri, String relativeUri, Boolean dontEscape)
at System.Uri..ctor(Uri baseUri, String relativeUri)
karelz
changed the title
Uri(Uri, String) throws NullReferenceException for certain relativeUri values
[Desktop] Uri(Uri, String) throws NullReferenceException for certain relativeUri values
Mar 23, 2018
This will also throw the expected exception on .NET Framework 4.7.2
System.UriFormatException occurred
Message=Invalid URI: The Authority/Host could not be parsed.
StackTrace:
at System.Uri.CreateThis(String uri, Boolean dontEscape, UriKind uriKind)
at System.Uri.CreateUri(Uri baseUri, String relativeUri, Boolean dontEscape)
at System.Uri..ctor(Uri baseUri, String relativeUri)
This situation is actually quite interesting. For compatibility reasons, we usually allow creation of relative URIs when there is a scheme but no host. That's based on section 5.4.2 of the RFC:
Some parsers allow the scheme name to be present in a relative
reference if it is the same as the base URI scheme. This is
considered to be a loophole in prior specifications of partial URI
[RFC1630]. Its use should be avoided but is allowed for backward
compatibility.
"http:g" = "http:g" ; for strict parsers
/ "http://a/b/c/g" ; for backward compatibility
It looks like we're running into a situation where we're disallowing that behavior. I think it's worth looking into why that is. I think we should keep this issue open to track that investigation, but leave it in future for now.
Short reproduction from C# interactive in Visual Studio 2017 15.6.4 on Windows 10 1709 (I'd assume this runs under .NET 4.7.1):
The exception type is unexpected, I would expect a
UriFormatException
to be thrown.:
to%3a
works fine%c3%b6
toa
yields a better exception:System.UriFormatException: Invalid URI: The Authority/Host could not be parsed.
So there seems to be something going on with the UTF-8 decoding combined with special case when a protocol is at start of the string.
(The problem is the same under mono 5.4.1.6 on macOS)
[EDIT] Update code formatting by @karelz
The text was updated successfully, but these errors were encountered: