ColacX
ColacX

Reputation: 4042

Bug? System.UriFormatException: Invalid URI: The URI scheme is not valid

The strings are identical but when passed as a variable it is not valid?

What the hell is going on? Is it a language bug? I'm running this in C# .Net Core

var postUrl = "​http://www.contoso.com";
var postUri = new Uri("http://www.contoso.com"); // works
var uri = new Uri(postUrl); // does not work

Upvotes: 1

Views: 3631

Answers (2)

Umang
Umang

Reputation: 875

If you pulling your hair, then it because there is space after first opening quote in postUrl. Please remove that space & your bug will be begone. enter image description here

Upvotes: 8

ColacX
ColacX

Reputation: 4042

Worked around the problem by using.

var postUrl = "​http://www.contoso.com";
var uriBuilder = new UriBuilder(postUrl);
var uri = uriBuilder.Uri

Still wondering wtf?

Just the daily wtf of a programmer doing his job.

Upvotes: 0

Related Questions