Blazor webassembly library System.IO.Path.GetDirectoryName and GetFileName broken in 5.0
Describe the bug
Under .NET Core 3.1.9 in a hosted Blazor WebAssembly app, client-side calls to System.IO.Path.GetDirectoryName and GetFileName behave identically to a server app (.NET Framework or Core). But under .NET 5.0 the parsing does not work correctly when using Windows format paths that use a foreslash (\). It works correctly with backslashes (/).
To Reproduce
I created identical projects from the default template (Index, Counter, Weather) in both 3.1.9 and 5.0. The I modified Counter slightly to include an input for a path string and a button to apply both GetDirectoryName and GetFileName.
Code listing in Counter.razor:
@page "/counter"
<h1>Counter</h1>
<p>Current count: @currentCount</p>
<button class="btn btn-primary" @onclick="IncrementCount">Click me</button>
<br />
<input type="text" @bind="FullPath" />
<br />
<div>@Directory</div>
<div>@Filename</div>
<button class="btn btn-primary" @onclick="ParsePath">Click me</button>
@code {
private int currentCount = 0;
private string FullPath { get; set; }
private string Directory { get; set; }
private string Filename { get; set; }
private void ParsePath(MouseEventArgs e)
{
this.Directory = System.IO.Path.GetDirectoryName(this.FullPath);
this.Filename = System.IO.Path.GetFileName(this.FullPath);
}
private void IncrementCount()
{
currentCount++;
}
}
If you enter a web style path with backslashes the parsing output it correct in both 3.1.9. With Windows style foreslashes it fails (no error, but parsing is incorrect/does not occur) in 5.0.
3.1.9

5.0

Exceptions (if any)
No exception but code does not work as expected.
Further technical details
3.1.9 / 5.0
.NET SDK (reflecting any global.json): Version: 5.0.100 Commit: 5044b93829
Runtime Environment: OS Name: Windows OS Version: 10.0.18362 OS Platform: Windows RID: win10-x64 Base Path: C:\Program Files\dotnet\sdk\5.0.100\
Host (useful for support): Version: 5.0.0 Commit: cf258a14b7
.NET SDKs installed: 2.1.509 [C:\Program Files\dotnet\sdk] 2.1.511 [C:\Program Files\dotnet\sdk] 2.1.512 [C:\Program Files\dotnet\sdk] 2.1.513 [C:\Program Files\dotnet\sdk] 2.1.514 [C:\Program Files\dotnet\sdk] 2.1.515 [C:\Program Files\dotnet\sdk] 2.1.516 [C:\Program Files\dotnet\sdk] 2.1.517 [C:\Program Files\dotnet\sdk] 2.1.519 [C:\Program Files\dotnet\sdk] 3.0.101 [C:\Program Files\dotnet\sdk] 3.1.201 [C:\Program Files\dotnet\sdk] 5.0.100 [C:\Program Files\dotnet\sdk]
.NET runtimes installed: Microsoft.AspNetCore.All 2.1.13 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.All 2.1.15 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.All 2.1.16 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.All 2.1.17 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.All 2.1.18 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.All 2.1.19 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.All 2.1.20 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.All 2.1.21 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.All 2.1.23 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.App 2.1.13 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 2.1.15 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 2.1.16 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 2.1.17 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 2.1.18 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 2.1.19 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 2.1.20 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 2.1.21 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 2.1.23 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 3.0.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 3.0.1 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 3.1.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 3.1.3 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 3.1.9 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 5.0.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.NETCore.App 2.1.13 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.1.15 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.1.16 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.1.17 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.1.18 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.1.19 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.1.20 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.1.21 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.1.23 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 3.0.1 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 3.1.2 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 3.1.3 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 3.1.9 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 5.0.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.WindowsDesktop.App 3.0.1 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 3.1.3 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 3.1.9 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 5.0.0 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
To install additional .NET runtimes or SDKs: https://aka.ms/dotnet-download
Visual Studio 2019 16.8.1
@JoelW187 thanks for contacting us.
This is likely a change in behavior when we switched from the mono BCL to the runtime BCL
Yes, I suspect that as well. But it's a breaking change and, more importantly, it behaves differently between the WebAssembly version and the Framework/Core Runtime version.
, it behaves differently between the WebAssembly version and the Framework/Core Runtime version.
Wouldn't we expect Blazor in 5.0 to work like other .NET 5.0 apps, since they converged onto 5.0 libraries?
Maybe this should be listed in https://docs.microsoft.com/en-us/dotnet/core/compatibility/3.1-5.0
@lewing this is odd breaking change
@marek-safar a wasm specific work around for this case was added to mono/mono that was not replicated here https://github.com/mono/mono/pull/19488 The current behavior in 5 is the unix behavior which matches what the filesystem can actually load. I'd like to understand the use case better before we consider recreating that situation.
cc @kjpou1
To expand a little the choice to allow parsing windows paths in the browser was based on the idea that it would improve compatibility with server side Blazor. In reality .NET (and by extension server side Blazor) parses System.IO.Path and System.Uri differently depending what kind of system is hosting the service so altering wasm specific parsing really just adds complication while breaking the overall logic of parsing matching the host.
@JoelW187 while we discuss the ultimate resolution here, are you able to work around this using System.Uri
var uri = new Uri("c:\\dir\\file");
var filename = System.IO.Path.GetFileName(uri.AbsolutePath); // filename == "file"
var directory = System.IO.Path.GetDirectoryName(uri.AbsolutePath) // directory == "c:/dir"
Agree that an understanding of the Use Case is needed first. I tend to agree with dan above with respect to Blazor and .NET 5.0 and of course it should be listed as well in https://docs.microsoft.com/en-us/dotnet/core/compatibility/3.1-5.0
The same modification from mono did move over:
https://github.com/dotnet/runtime/blob/master/src/mono/mono/metadata/w32file.c#L791-L793
but when executing: Console.WriteLine(Path.AltDirectorySeparatorChar); what is printed is /
Here is the code that now controls the Path.AltDirectorySeparatorChar value https://github.com/dotnet/runtime/blob/master/src/libraries/System.Private.CoreLib/src/System/IO/PathInternal.Unix.cs#L15
Unfortunately the simple change of
internal const char AltDirectorySeparatorChar = '\\';
Also affects other parts of the system so more analysis will be needed before changing this.
Example message trying to run tests:
info: console.debug: MONO_WASM: Initializing mono runtime
info: console.debug: MONO_WASM: ICU data archive(s) loaded, disabling invariant mode
info: console.debug: mono_wasm_runtime_ready fe00e07a-5519-4dfe-b35a-f867dbaf2e28
info: Initializing.....
info: WASM-ERR: ---- DEBUG ASSERTION FAILED ----
info: WASM-ERR: ---- Assert Short Message ----
info: WASM-ERR:
info: WASM-ERR: ---- Assert Long Message ----
info: WASM-ERR:
info: WASM-ERR: at System.Diagnostics.DebugProvider.Fail(String message, String detailMessage)
info: WASM-ERR: at System.Diagnostics.Debug.Fail(String message, String detailMessage)
info: WASM-ERR: at System.Diagnostics.Debug.Assert(Boolean condition, String message, String detailMessage)
info: WASM-ERR: at System.Diagnostics.Debug.Assert(Boolean condition)
info: WASM-ERR: at System.IO.PathInternal.IsDirectorySeparator(Char c)
info: WASM-ERR: at System.IO.PathInternal.GetRootLength(ReadOnlySpan`1 path)
info: WASM-ERR: at System.IO.Path.GetDirectoryNameOffset(ReadOnlySpan`1 path)
info: WASM-ERR: at System.IO.Path.GetDirectoryName(String path)
info: WASM-ERR: at Xunit.Xunit2Discoverer.GetXunitExecutionAssemblyPath(AppDomainSupport appDomainSupport, String assemblyFileName, Boolean verifyTestAssemblyExists)
info: WASM-ERR: at Xunit.Xunit2Discoverer..ctor(AppDomainSupport appDomainSupport, ISourceInformationProvider sourceInformationProvider, String assemblyFileName, String configFileName, Boolean shadowCopy, String shadowCopyFolder, IMessageSink diagnosticMessageSink, Boolean verifyAssembliesOnDisk)
info: WASM-ERR: at Xunit.Xunit2..ctor(AppDomainSupport appDomainSupport, ISourceInformationProvider sourceInformationProvider, String assemblyFileName, String configFileName, Boolean shadowCopy, String shadowCopyFolder, IMessageSink diagnosticMessageSink, Boolean verifyTestAssemblyExists)
info: WASM-ERR: at Microsoft.DotNet.XHarness.TestRunners.Xunit.ThreadlessXunitTestRunner.Run(String assemblyFileName, Boolean printXml, XunitFilters filters)
info: WASM-ERR: at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[<Run>d__0](<Run>d__0& stateMachine)
info: WASM-ERR: at Microsoft.DotNet.XHarness.TestRunners.Xunit.ThreadlessXunitTestRunner.Run(String assemblyFileName, Boolean printXml, XunitFilters filters)
info: WASM-ERR: at Microsoft.DotNet.XHarness.TestRunners.Xunit.WasmApplicationEntryPoint.Run()
info: WASM-ERR: at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[<Run>d__24](<Run>d__24& stateMachine)
info: WASM-ERR: at Microsoft.DotNet.XHarness.TestRunners.Xunit.WasmApplicationEntryPoint.Run()
info: WASM-ERR: at SimpleWasmTestRunner.Main(String[] args)
info: WASM-ERR: at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[<Main>d__0](<Main>d__0& stateMachine)
info: WASM-ERR: at SimpleWasmTestRunner.Main(String[] args)
fail: 11:14:15.5300200 CLR: Managed code called FailFast, saying " at System.Diagnostics.DebugProvider.Fail(String message, String detailMessage)
fail: 11:14:15.5303370 at System.Diagnostics.Debug.Fail(String message, String detailMessage)
fail: 11:14:15.5303750 at System.Diagnostics.Debug.Assert(Boolean condition, String message, String detailMessage)
fail: 11:14:15.5303870 at System.Diagnostics.Debug.Assert(Boolean condition)
fail: 11:14:15.5303900 at System.IO.PathInternal.IsDirectorySeparator(Char c)
fail: 11:14:15.5303930 at System.IO.PathInternal.GetRootLength(ReadOnlySpan`1 path)
fail: 11:14:15.5303960 at System.IO.Path.GetDirectoryNameOffset(ReadOnlySpan`1 path)
fail: 11:14:15.5303990 at System.IO.Path.GetDirectoryName(String path)
fail: 11:14:15.5304020 at Xunit.Xunit2Discoverer.GetXunitExecutionAssemblyPath(AppDomainSupport appDomainSupport, String assemblyFileName, Boolean verifyTestAssemblyExists)
fail: 11:14:15.5304630 at Xunit.Xunit2Discoverer..ctor(AppDomainSupport appDomainSupport, ISourceInformationProvider sourceInformationProvider, String assemblyFileName, String configFileName, Boolean shadowCopy, String shadowCopyFolder, IMessageSink diagnosticMessageSink, Boolean verifyAssembliesOnDisk)
fail: 11:14:15.5304760 at Xunit.Xunit2..ctor(AppDomainSupport appDomainSupport, ISourceInformationProvider sourceInformationProvider, String assemblyFileName, String configFileName, Boolean shadowCopy, String shadowCopyFolder, IMessageSink diagnosticMessageSink, Boolean verifyTestAssemblyExists)
fail: 11:14:15.5304790 at Microsoft.DotNet.XHarness.TestRunners.Xunit.ThreadlessXunitTestRunner.Run(String assemblyFileName, Boolean printXml, XunitFilters filters)
fail: 11:14:15.5304820 at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[<Run>d__0](<Run>d__0& stateMachine)
fail: 11:14:15.5304900 at Microsoft.DotNet.XHarness.TestRunners.Xunit.ThreadlessXunitTestRunner.Run(String assemblyFileName, Boolean printXml, XunitFilters filters)
fail: 11:14:15.5304930 at Microsoft.DotNet.XHarness.TestRunners.Xunit.WasmApplicationEntryPoint.Run()
fail: 11:14:15.5304960 at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[<Run>d__24](<Run>d__24& stateMachine)
fail: 11:14:15.5305000 at Microsoft.DotNet.XHarness.TestRunners.Xunit.WasmApplicationEntryPoint.Run()
fail: 11:14:15.5305020 at SimpleWasmTestRunner.Main(String[] args)
fail: 11:14:15.5305230 at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[<Main>d__0](<Main>d__0& stateMachine)
fail: 11:14:15.5305270 at SimpleWasmTestRunner.Main(String[] args)"
Also causes failures when running the chrome driver:
Starting ChromeDriver 86.0.4240.22 (398b0743353ff36fb1b82468f63a3a93b4e2e89e-refs/branch-heads/4240@{#378}) on port 60713
Only local connections are allowed.
Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.
ChromeDriver was started successfully.
info: browser: Console websocket connected.
info: URL ARG: arg=--run
info: URL ARG: arg=WasmTestRunner.dll
info: URL ARG: arg=System.Private.Runtime.InteropServices.JavaScript.Tests.dll
info: URL ARG: arg=-notrait
info: URL ARG: arg=category=OuterLoop
info: URL ARG: arg=-notrait
info: URL ARG: arg=category=failing
info: Arguments: --run,WasmTestRunner.dll,System.Private.Runtime.InteropServices.JavaScript.Tests.dll,-notrait,category=OuterLoop,-notrait,category=failing
info: MONO_WASM: Initializing mono runtime
info: MONO_WASM: ICU data archive(s) loaded, disabling invariant mode
info: mono_wasm_runtime_ready
info: Initializing.....
info: WASM-ERR: ---- DEBUG ASSERTION FAILED ----
info: WASM-ERR: ---- Assert Short Message ----
info: WASM-ERR:
info: WASM-ERR: ---- Assert Long Message ----
info: WASM-ERR:
info: WASM-ERR: at System.Diagnostics.DebugProvider.Fail(String message, String detailMessage)
info: WASM-ERR: at System.Diagnostics.Debug.Fail(String message, String detailMessage)
info: WASM-ERR: at System.Diagnostics.Debug.Assert(Boolean condition, String message, String detailMessage)
info: WASM-ERR: at System.Diagnostics.Debug.Assert(Boolean condition)
info: WASM-ERR: at System.IO.PathInternal.IsDirectorySeparator(Char c)
info: WASM-ERR: at System.IO.PathInternal.GetRootLength(ReadOnlySpan`1 path)
info: WASM-ERR: at System.IO.Path.GetDirectoryNameOffset(ReadOnlySpan`1 path)
info: WASM-ERR: at System.IO.Path.GetDirectoryName(String path)
info: WASM-ERR: at Xunit.Xunit2Discoverer.GetXunitExecutionAssemblyPath(AppDomainSupport appDomainSupport, String assemblyFileName, Boolean verifyTestAssemblyExists)
info: WASM-ERR: at Xunit.Xunit2Discoverer..ctor(AppDomainSupport appDomainSupport, ISourceInformationProvider sourceInformationProvider, String assemblyFileName, String configFileName, Boolean shadowCopy, String shadowCopyFolder, IMessageSink diagnosticMessageSink, Boolean verifyAssembliesOnDisk)
info: WASM-ERR: at Xunit.Xunit2..ctor(AppDomainSupport appDomainSupport, ISourceInformationProvider sourceInformationProvider, String assemblyFileName, String configFileName, Boolean shadowCopy, String shadowCopyFolder, IMessageSink diagnosticMessageSink, Boolean verifyTestAssemblyExists)
info: WASM-ERR: at Microsoft.DotNet.XHarness.TestRunners.Xunit.ThreadlessXunitTestRunner.Run(String assemblyFileName, Boolean printXml, XunitFilters filters)
info: WASM-ERR: at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[<Run>d__0](<Run>d__0& stateMachine)
info: WASM-ERR: at Microsoft.DotNet.XHarness.TestRunners.Xunit.ThreadlessXunitTestRunner.Run(String assemblyFileName, Boolean printXml, XunitFilters filters)
info: WASM-ERR: at Microsoft.DotNet.XHarness.TestRunners.Xunit.WasmApplicationEntryPoint.Run()
info: WASM-ERR: at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[<Run>d__24](<Run>d__24& stateMachine)
info: WASM-ERR: at Microsoft.DotNet.XHarness.TestRunners.Xunit.WasmApplicationEntryPoint.Run()
info: WASM-ERR: at SimpleWasmTestRunner.Main(String[] args)
info: WASM-ERR: at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[<Main>d__0](<Main>d__0& stateMachine)
info: WASM-ERR: at SimpleWasmTestRunner.Main(String[] args)
info: CLR: Managed code called FailFast, saying " at System.Diagnostics.DebugProvider.Fail(String message, String detailMessage)
at System.Diagnostics.Debug.Fail(String message, String detailMessage)
at System.Diagnostics.Debug.Assert(Boolean condition, String message, String detailMessage)
at System.Diagnostics.Debug.Assert(Boolean condition)
at System.IO.PathInternal.IsDirectorySeparator(Char c)
at System.IO.PathInternal.GetRootLength(ReadOnlySpan`1 path)
at System.IO.Path.GetDirectoryNameOffset(ReadOnlySpan`1 path)
at System.IO.Path.GetDirectoryName(String path)
at Xunit.Xunit2Discoverer.GetXunitExecutionAssemblyPath(AppDomainSupport appDomainSupport, String assemblyFileName, Boolean verifyTestAssemblyExists)
at Xunit.Xunit2Discoverer..ctor(AppDomainSupport appDomainSupport, ISourceInformationProvider sourceInformationProvider, String assemblyFileName, String configFileName, Boolean shadowCopy, String shadowCopyFolder, IMessageSink diagnosticMessageSink, Boolean verifyAssembliesOnDisk)
at Xunit.Xunit2..ctor(AppDomainSupport appDomainSupport, ISourceInformationProvider sourceInformationProvider, String assemblyFileName, String configFileName, Boolean shadowCopy, String shadowCopyFolder, IMessageSink diagnosticMessageSink, Boolean verifyTestAssemblyExists)
at Microsoft.DotNet.XHarness.TestRunners.Xunit.ThreadlessXunitTestRunner.Run(String assemblyFileName, Boolean printXml, XunitFilters filters)
at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[<Run>d__0](<Run>d__0& stateMachine)
at Microsoft.DotNet.XHarness.TestRunners.Xunit.ThreadlessXunitTestRunner.Run(String assemblyFileName, Boolean printXml, XunitFilters filters)
at Microsoft.DotNet.XHarness.TestRunners.Xunit.WasmApplicationEntryPoint.Run()
at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[<Run>d__24](<Run>d__24& stateMachine)
at Microsoft.DotNet.XHarness.TestRunners.Xunit.WasmApplicationEntryPoint.Run()
at SimpleWasmTestRunner.Main(String[] args)
at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[<Main>d__0](<Main>d__0& stateMachine)
at SimpleWasmTestRunner.Main(String[] args)"
info: WASM-ERR:
info: WASM-ERR: Unhandled Exception:
info: WASM-ERR: System.Diagnostics.DebugProvider+DebugAssertException: at System.Diagnostics.DebugProvider.Fail(String message, String detailMessage)
info: WASM-ERR: at System.Diagnostics.Debug.Fail(String message, String detailMessage)
info: WASM-ERR: at System.Diagnostics.Debug.Assert(Boolean condition, String message, String detailMessage)
info: WASM-ERR: at System.Diagnostics.Debug.Assert(Boolean condition)
info: WASM-ERR: at System.IO.PathInternal.IsDirectorySeparator(Char c)
info: WASM-ERR: at System.IO.PathInternal.GetRootLength(ReadOnlySpan`1 path)
info: WASM-ERR: at System.IO.Path.GetDirectoryNameOffset(ReadOnlySpan`1 path)
info: WASM-ERR: at System.IO.Path.GetDirectoryName(String path)
info: WASM-ERR: at Xunit.Xunit2Discoverer.GetXunitExecutionAssemblyPath(AppDomainSupport appDomainSupport, String assemblyFileName, Boolean verifyTestAssemblyExists)
info: WASM-ERR: at Xunit.Xunit2Discoverer..ctor(AppDomainSupport appDomainSupport, ISourceInformationProvider sourceInformationProvider, String assemblyFileName, String configFileName, Boolean shadowCopy, String shadowCopyFolder, IMessageSink diagnosticMessageSink, Boolean verifyAssembliesOnDisk)
info: WASM-ERR: at Xunit.Xunit2..ctor(AppDomainSupport appDomainSupport, ISourceInformationProvider sourceInformationProvider, String assemblyFileName, String configFileName, Boolean shadowCopy, String shadowCopyFolder, IMessageSink diagnosticMessageSink, Boolean verifyTestAssemblyExists)
info: WASM-ERR: at Microsoft.DotNet.XHarness.TestRunners.Xunit.ThreadlessXunitTestRunner.Run(String assemblyFileName, Boolean printXml, XunitFilters filters)
info: WASM-ERR: at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[<Run>d__0](<Run>d__0& stateMachine)
info: WASM-ERR: at Microsoft.DotNet.XHarness.TestRunners.Xunit.ThreadlessXunitTestRunner.Run(String assemblyFileName, Boolean printXml, XunitFilters filters)
info: WASM-ERR: at Microsoft.DotNet.XHarness.TestRunners.Xunit.WasmApplicationEntryPoint.Run()
info: WASM-ERR: at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[<Run>d__24](<Run>d__24& stateMachine)
info: WASM-ERR: at Microsoft.DotNet.XHarness.TestRunners.Xunit.WasmApplicationEntryPoint.Run()
info: WASM-ERR: at SimpleWasmTestRunner.Main(String[] args)
info: WASM-ERR: at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[<Main>d__0](<Main>d__0& stateMachine)
info: WASM-ERR: at SimpleWasmTestRunner.Main(String[] args)
info: ABORT: undefined
info: Stacktrace:
info: Error
at Object.onAbort (http://127.0.0.1:60729/runtime.js:210:13)
at abort (http://127.0.0.1:60729/dotnet.js:1435:22)
at _abort (http://127.0.0.1:60729/dotnet.js:5739:7)
at ves_icall_System_Environment_FailFast (http://127.0.0.1:60729/dotnet.wasm:wasm-function[1854]:0xaffb4)
at ves_icall_System_Environment_FailFast_raw (http://127.0.0.1:60729/dotnet.wasm:wasm-function[1935]:0xb3a1a)
at do_icall (http://127.0.0.1:60729/dotnet.wasm:wasm-function[219]:0x2a5bc)
at do_icall_wrapper (http://127.0.0.1:60729/dotnet.wasm:wasm-function[182]:0x28e17)
at interp_exec_method (http://127.0.0.1:60729/dotnet.wasm:wasm-function[131]:0xb285)
at interp_runtime_invoke (http://127.0.0.1:60729/dotnet.wasm:wasm-function[130]:0x8e24)
at mono_jit_runtime_invoke (http://127.0.0.1:60729/dotnet.wasm:wasm-function[6355]:0x1cac43)
info: WASM EXIT 1
I do not think there is anything to fix. We just need to document it as a breaking change. It makes much more sense for paths on wasm to behave as Unix, not as Windows.
Thanks for the information @jkotas
@lewing Yes, I'm able to work around it, thanks. @jkotas Let me play devil's advocate -- the reason I encountered the issue was that we have a document library stored on Windows servers and our database stores a relative path that I was parsing to pass as a query string parameter -- not far fetched or unusual. Since .NET 5.0 is mixed platform what about an overload to specify a platform like GetDirectoryName(string, PlatformOS.Windows)?
All APIs on System.IO.Path and elsewhere follow the rules of the OS that the program is running on. I do not think it would make sense to add an overload that activates some other OS simulator to all these APIs.
Agreed. This issue isn't Browser specific and any Browser specific work around only makes the situation worse. Proposals for new APIs or extensions to existing ones belong in a new cross platform issue. Closing.