Uri Constructor (String)

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Initializes a new instance of the Uri class with the specified URI.

Namespace:  System
Assembly:  System (in System.dll)


Public Sub New ( _
    uriString As String _
public Uri(
    string uriString



Exception Condition

uriString is nulla null reference (Nothing in Visual Basic).


uriString is empty.


The scheme specified in uriString is not correctly formed. See CheckSchemeName.


uriString contains too many slashes.


The password specified in uriString is not valid.


The host name specified in uriString is not valid.


The file name specified in uriString is not valid.


The user name specified in uriString is not valid.


The host or authority name specified in uriString cannot be terminated by backslashes.


The port number specified in uriString is not valid or cannot be parsed.


The length of uriString exceeds 65519 characters.


The length of the scheme specified in uriString exceeds 1024 characters.


There is an invalid character sequence in uriString.


The MS-DOS path specified in uriString must start with c:\\.


This constructor creates a Uri instance from a URI string. It parses the URI, puts it in canonical format, and makes any required escape encodings.

This constructor assumes that the string parameter references an absolute URI and is equivalent to calling the Uri constructor with UriKind set to Absolute. If the string parameter passed to the constructor is a relative URI, this constructor will throw a UriFormatException.

The uriString can be poorly formed and can still be used to construct a Uri instance. The Silverlight runtime will try to correct some minor issues with a poorly-formed string when this constructor is called to create a Uri instance.

This constructor allows a Silverlight application to create a Uri instance for many schemes as described in the Scheme property. However, only Uri instances for the UriSchemeHttp or UriSchemeHttps schemes are supported by the WebClient and HTTP classes in the System.Net namespace.

This constructor does not ensure that the Uri refers to an accessible resource.

Silverlight-based applications are cross-platform, so they run in most modern Web browsers, including Apple Safari version 2.0 and later on Apple Mac OS X. However, Uri(String) does not convert backslashes in the uriString parameter to forward slashes in the Uri on Apple Mac OS X.


The following example creates a Uri instance with the URI "http://www.contoso.com/".

  Dim myUri As New Uri("http://www.contoso.com/")

Uri myUri = new Uri("http://www.contoso.com/");

Version Information


Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Xbox 360, Windows Phone OS 7.0


For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.