Problem with (string, string) constructor when extending the Uri class

J

Jan Aagaard

I have the following rather simple code, where I want to extend the
Uri class in order to add a couple of handy methods.

public class Uri2 : Uri
{
public Uri2(string baseUri, string relativeUri)
: base(baseUri, relativeUri)
{ }
}

But I get the following error when compiling: "The best overloaded
method match for 'System.Uri.Uri(string, bool)' has some invalid
arguments", and the problem seems to be that there is another
overloaded constructor for the Uri class that takes two arguments, the
second one being a boolean in stead of a string.

I've tried casting the relativeUri explicitly and I've tried adding
the (string, bool) constructor to my Uri2 class, but no luck so far.

Note: The (string, bool) constructor for the Uri class has been made
obsolete. Could this the answer to the why the compiler is confused?

I guess that the answer is pretty straight forward if just you know C#
a little better than I do. Can anyone out there help?
 
J

Jon Skeet [C# MVP]

Jan Aagaard said:
I have the following rather simple code, where I want to extend the
Uri class in order to add a couple of handy methods.

public class Uri2 : Uri
{
public Uri2(string baseUri, string relativeUri)
: base(baseUri, relativeUri)
{ }
}

But I get the following error when compiling: "The best overloaded
method match for 'System.Uri.Uri(string, bool)' has some invalid
arguments", and the problem seems to be that there is another
overloaded constructor for the Uri class that takes two arguments, the
second one being a boolean in stead of a string.

No, the problem is that there isn't a Uri(string,string) constructor.
There's Uri(Uri,Uri) and Uri(Uri,string) - did you mean one of those?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top