Val Nolav
Val Nolav

Reputation: 902

Invalid Uri: The Uri scheme is not valid

I am trying to make a connection via HttpWebRequest. I am reading url links from a text file. However, I am getting 'System.UriFormatException' error.

I have tried to add http:// in front of the url links in my text file. But the result is the same.

What can be the solution?

Upvotes: 4

Views: 40805

Answers (2)

Daniel Becroft
Daniel Becroft

Reputation: 716

If the error only occurs when reading the values from a file, but not when assigned directly to a string variable, then I'm guessing that there are extra characters being read (quotes, escaped characters, carriage-return/line feeds, etc).

Try reading the first value into a string, and then comparing that to what you expect in the explicit string value. Any differences should be obvious after that.

Upvotes: 10

Anson
Anson

Reputation: 2674

Without seeing code it's impossible to tell what you're trying to do. But you can start by looking at the Message property of the UriFormatException class. Message is a string that explains the reason for the exception.

Upvotes: 1

Related Questions