I am getting this error when trying to assemble an absolute file URI, using a relative file uri in the first place, with the file:
or file:./
syntax for the relative URI.
Any idea why this behaves different under Linux? It is deliberately added to an absolute URI part, to be without authority or drive letter.
The error occurs under Linux only (Docker base image mcr.microsoft.com/dotnet/sdk:8.0), not under Windows. As a side note, the code is compiled on Windows and executed as test in a shared folder in the Docker container.
<code> [TestMethod]
[DataRow("first/second/filename.txt", null, "/first/second/filename.txt")] // OK
[DataRow("file:./first/second/filename.txt", "file", "/first/second/filename.txt")] // fails
[DataRow("file:first/second/filename.txt", "file", "/first/second/filename.txt")] // fails
public void MyFileUriTest_Relative(string uriString, string? expScheme, string? expPathAndQuery)
{
var uri = new Uri(uriString, UriKind.Relative);
var absBase = new Uri("file:///", UriKind.Absolute);
var absUri = new Uri(absBase, uri); // error here!
// other test code, irrelevant here.
}
</code>
<code> [TestMethod]
[DataRow("first/second/filename.txt", null, "/first/second/filename.txt")] // OK
[DataRow("file:./first/second/filename.txt", "file", "/first/second/filename.txt")] // fails
[DataRow("file:first/second/filename.txt", "file", "/first/second/filename.txt")] // fails
public void MyFileUriTest_Relative(string uriString, string? expScheme, string? expPathAndQuery)
{
var uri = new Uri(uriString, UriKind.Relative);
var absBase = new Uri("file:///", UriKind.Absolute);
var absUri = new Uri(absBase, uri); // error here!
// other test code, irrelevant here.
}
</code>
[TestMethod]
[DataRow("first/second/filename.txt", null, "/first/second/filename.txt")] // OK
[DataRow("file:./first/second/filename.txt", "file", "/first/second/filename.txt")] // fails
[DataRow("file:first/second/filename.txt", "file", "/first/second/filename.txt")] // fails
public void MyFileUriTest_Relative(string uriString, string? expScheme, string? expPathAndQuery)
{
var uri = new Uri(uriString, UriKind.Relative);
var absBase = new Uri("file:///", UriKind.Absolute);
var absUri = new Uri(absBase, uri); // error here!
// other test code, irrelevant here.
}
The stack trace is:
<code>Uri.CreateThis(String uri, Boolean dontEscape, UriKind uriKind, UriCreationOptions& creationOptions)
Uri.ctor(Uri baseUri, Uri relativeUri)
MyFileUriTests.MyFileUriTest_Relative(String uriString, String expScheme, String expPathAndQuery) line 101
(+ test stack trace)
</code>
<code>Uri.CreateThis(String uri, Boolean dontEscape, UriKind uriKind, UriCreationOptions& creationOptions)
Uri.ctor(Uri baseUri, Uri relativeUri)
MyFileUriTests.MyFileUriTest_Relative(String uriString, String expScheme, String expPathAndQuery) line 101
(+ test stack trace)
</code>
Uri.CreateThis(String uri, Boolean dontEscape, UriKind uriKind, UriCreationOptions& creationOptions)
Uri.ctor(Uri baseUri, Uri relativeUri)
MyFileUriTests.MyFileUriTest_Relative(String uriString, String expScheme, String expPathAndQuery) line 101
(+ test stack trace)
1