Uri.MakeRelativeUri Behavior On Mono

I see some strange (for me, anyway) behavior when using MakeRelativeUri on Mono (2.6.7). Take the following example:

var uri1 = new Uri("/somepath/someothersubpath/");
var uri2 = new Uri("/somepath/img/someimg.jpg");

var uri3 = uri1.MakeRelativeUri(uri2);
Console.WriteLine(uri3.OriginalString);

I expect this to print "../img/someimg.jpg", but I get"img/someimg.jpg"

A friend confirmed using windows / visual studio that he would get the expected result by adding an additional slash to the beginning of the line (I tried this too, and to no avail).

I'm not sure if this is a problem with the Uri class in mono, or if my understanding of how the URI class should work is erroneous, but any advice that can help me get the expected result will be very helpful.

Thank,

Alex

+3
source share
2 answers

, someothersubpath , .

, , , , - :

var uri1 = new Uri("/somepath/someothersubpath/anything");
var uri2 = new Uri("/somepath/img/someimg.jpg");

var uri3 = uri1.MakeRelativeUri(uri2);
Console.WriteLine(uri3.OriginalString);
+1

Microsoft.NET Uri.MakeRelativeUri , InvalidOperationException Uris.

, , : " URI: URI ". :

    var uri1 = new Uri("/somepath/someothersubpath/", UriKind.RelativeOrAbsolute);
    var uri2 = new Uri("/somepath/img/someimg.jpg", UriKind.RelativeOrAbsolute);

    var uri3 = uri1.MakeRelativeUri(uri2);

InvalidOperationException: URI. , .

, , Mono .NET.

+1

Source: https://habr.com/ru/post/1764324/


All Articles