Skip to content

[wasi][coreclr] AppContext.BaseDirectory is "/" while assemblies are bundled under /managed #134952

Description

@lewing

Description

On CoreCLR WASI, AppContext.BaseDirectory is /, but the app bundle places the app and framework assemblies under /managed:

  • wasihost (src/native/corehost/wasihost/wasihost.cpp) sets TRUSTED_PLATFORM_ASSEMBLIES and APP_PATHS (the entry assembly directory, /managed/) but not APP_CONTEXT_BASE_DIRECTORY.
  • CoreLib then falls back to AppContext.Browser.cs, which is shared with WASI and returns /.
  • The test harness preopens the bundle directory (--dir=.) and sets CORE_ROOT=/managed.

Code that locates files next to the application therefore looks in the wrong directory. In the CoreCLR WASI library test runs on #134813:

  • System.Runtime.Loader.Tests: 19 of its 22 failures are FileNotFoundException : Could not find file '/System.Reflection.Metadata.ApplyUpdate.Test...dll', and one more is the same for a System.Runtime.Loader test assembly. The tests build the path from AppContext.BaseDirectory, and the file is in /managed.
  • System.Diagnostics.TraceSource.Config.Tests (8 of 8): FileNotFoundException : Could not find file '/testhost_ConfigWithRuntime.config'.

Test content deployed through WasmFilesToIncludeInFileSystem lands at the bundle root, not under managed/. So the fix has to keep both working: assemblies located through AppContext.BaseDirectory, and content opened relative to the working directory (/).

Options

  1. Have wasihost set APP_CONTEXT_BASE_DIRECTORY to the entry assembly directory, as other hosts do, and deploy test content into the same directory.
  2. Bundle the assemblies at the root instead of under managed/, so the base directory, working directory and assembly location coincide.

Note

This issue was drafted with the help of GitHub Copilot.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    arch-wasmWebAssembly architecturearea-Hostos-wasiRelated to WASI variant of arch-wasm

    Type

    No type

    Projects

    • Status
      No status

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions