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

  • Thread starter Thread starter Jan Aagaard
  • Start date Start date
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?
 
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?
 
Back
Top