Home All Groups Group Topic Archive Search About

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

Author
27 Mar 2007 8:51 PM
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?

Author
27 Mar 2007 9:07 PM
Jon Skeet [C# MVP]
Jan Aagaard <janaaga***@gmail.com> wrote:
Show quote
> 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?

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet   Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too

AddThis Social Bookmark Button