Skip to content

[Wasm] cannot load assets by mono_download_assets at out of AppBundle #69259

Closed

Description

Description

Summary: Cannot initialize dotnet runtime except at location AppBundle directory.

In the template, we can run the sample code by executing the following command in the directory where the assets exist after the build (AppBundle).

$ node main.cjs

https://github.com/dotnet/runtime/tree/51d51c1a6631b205b6ace381bbfd417b5c0e481d/src/mono/wasm/templates/templates/console

Then, from one directory up, run main.cjs in the following way to cause Failed to load config file ./mono-config.json Error: ENOENT: no such file or directory, open './mono-config.json'

I expected to find mono-config.json in the same path as the execution path, so I explicitly specified the path and it was successfully loaded.
The modified code is as follows...

const createDotnetRuntime = require("./dotnet.js");
const { resolve } = require("path");

async function main() {
  const { MONO } = await createDotnetRuntime({
    configSrc: resolve(__dirname, "mono-config.json"),
  });
  const app_args = process.argv.slice(2);
  await MONO.mono_run_main_and_exit("console.dll", app_args);
}
main();

But an error MONO_WASM: Error in mono_download_assets: Error: MONO_WASM: Fetch 'supportFiles/0_runtimeconfig.bin' for supportFiles/0_runtimeconfig.bin failed undefined undefined occurred.

Reproduction Steps

  1. dotnet new wasmconsole
  2. replace main.cjs with Snippet1 (below)
  3. dotnet publish -c Release
  4. cd bin/Release/net7.0/browser-wasm
  5. node AppBundle/main.cjs

Snippet1

const createDotnetRuntime = require("./dotnet.js");
const { resolve } = require("path");

async function main() {
  const { MONO } = await createDotnetRuntime({
    configSrc: resolve(__dirname, "mono-config.json"),
  });
  const app_args = process.argv.slice(2);
  await MONO.mono_run_main_and_exit("console.dll", app_args);
}
main();

Expected behavior

When initializing the dotnet runtime, it is possible to load assets other than assembly and resource even if the node runtime path is not the same path.

see:

if (sourcePrefix.trim() === "") {
if (asset.behavior === "assembly")
attemptUrl = locateFile(config.assembly_root + "/" + asset.name);
else if (asset.behavior === "resource") {
const path = asset.culture !== "" ? `${asset.culture}/${asset.name}` : asset.name;
attemptUrl = locateFile(config.assembly_root + "/" + path);
}
else
attemptUrl = asset.name;
} else {

Actual behavior

Only assembly can be resolved by path and cannot load vfs behavior file.

Regression?

No response

Known Workarounds

No response

Configuration

  • OS
    • macOS 12.3.1(21E258)
  • dotnet --version
    • 7.0.100-preview.4.22252.9
  • Node
    • v16.13.0

Other information

[2022-05-12T14:11:53.081Z] Worker process started and initialized.
[2022-05-12T14:11:54.118Z] Host lock lease acquired by instance ID '000000000000000000000000A572DD4C'.
[2022-05-12T14:13:04.993Z] Worker process started and initialized.
[2022-05-12T14:13:08.343Z] Executing 'Functions.HttpTrigger' (Reason='This function was programmatically called via the host APIs.', Id=f7e37082-4d19-45b3-ab6a-bebe8f2398e0)
[2022-05-12T14:13:08.362Z] HTTP trigger function processed a request.
[2022-05-12T14:13:08.366Z] {
[2022-05-12T14:13:08.366Z]   assembly_root: 'managed',
[2022-05-12T14:13:08.366Z]   debug_level: 0,
[2022-05-12T14:13:08.366Z]   assets: [
[2022-05-12T14:13:08.366Z]     { behavior: 'assembly', name: 'console.dll' },
[2022-05-12T14:13:08.366Z]     { behavior: 'assembly', name: 'System.Console.dll' },
[2022-05-12T14:13:08.366Z]     { behavior: 'assembly', name: 'System.Private.CoreLib.dll' },
[2022-05-12T14:13:08.367Z]     {
[2022-05-12T14:13:08.367Z]       behavior: 'assembly',
[2022-05-12T14:13:08.367Z]       name: 'System.Private.Runtime.InteropServices.JavaScript.dll'
[2022-05-12T14:13:08.367Z]     },
[2022-05-12T14:13:08.367Z]     { behavior: 'assembly', name: 'System.Private.Uri.dll' },
[2022-05-12T14:13:08.367Z]     { behavior: 'assembly', name: 'System.Runtime.dll' },
[2022-05-12T14:13:08.367Z]     {
[2022-05-12T14:13:08.367Z]       virtual_path: 'runtimeconfig.bin',
[2022-05-12T14:13:08.367Z]       behavior: 'vfs',
[2022-05-12T14:13:08.367Z]       name: 'supportFiles/0_runtimeconfig.bin'
[2022-05-12T14:13:08.367Z]     },
[2022-05-12T14:13:08.367Z]     { load_remote: false, behavior: 'icu', name: 'icudt.dat' },
[2022-05-12T14:13:08.367Z]     {
[2022-05-12T14:13:08.367Z]       virtual_path: '/usr/share/zoneinfo/',
[2022-05-12T14:13:08.367Z]       behavior: 'vfs',
[2022-05-12T14:13:08.367Z]       name: 'dotnet.timezones.blat'
[2022-05-12T14:13:08.367Z]     }
[2022-05-12T14:13:08.367Z]   ],
[2022-05-12T14:13:08.367Z]   remote_sources: [],
[2022-05-12T14:13:08.367Z]   environment_variables: {},
[2022-05-12T14:13:08.367Z]   runtime_options: [],
[2022-05-12T14:13:08.367Z]   globalization_mode: 'auto',
[2022-05-12T14:13:08.367Z]   diagnostic_tracing: false
[2022-05-12T14:13:08.368Z] }
[2022-05-12T14:13:08.368Z] '/Users/yk-yamada/Projects/github.com/yamachu/azure-functions-nodejs-with-csharp/dist/AppBundle/managed/console.dll' <- behavior: assembly
[2022-05-12T14:13:08.380Z] 'supportFiles/0_runtimeconfig.bin' <-  behavior: vfs
[2022-05-12T14:13:08.382Z] 'icudt.dat' <-  behavior: vfs
[2022-05-12T14:13:08.384Z] 'dotnet.timezones.blat' <-  behavior: vfs

I think we can run locateFile on any file type, but what is the reason for narrowing down the types?

if (sourcePrefix.trim() === "") {
if (asset.behavior === "assembly")
attemptUrl = locateFile(config.assembly_root + "/" + asset.name);
else if (asset.behavior === "resource") {
const path = asset.culture !== "" ? `${asset.culture}/${asset.name}` : asset.name;
attemptUrl = locateFile(config.assembly_root + "/" + path);
}
else
attemptUrl = asset.name;
} else {

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

Metadata

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions