dotnet/runtime

Loading a self-contained executable with custom runtime host returns error about missing .deps.json file

Open

#76,080 opened on 2022年9月23日

GitHub で見る
 (12 comments) (0 reactions) (0 assignees)C# (5,445 forks)batch import
area-Hostdocumentationhelp wanted

Repository metrics

Stars
 (17,886 stars)
PR merge metrics
 (平均マージ 12d 11h) (30d で 661 merged PRs)

説明

Description

Using hostfxr_initialize_for_dotnet_command_line to load a self-contained executable with a custom runtime host app fails due to a missing .deps.json file (even though it shouldn't be present in self-contained apps?).

Reproduction Steps

  1. Create a default .NET 6 console app project
  2. Publish it with the following settings:
  • Deployment mode: self-contained
  • Target runtime: win-x64
  • ✅ Produce single file
  1. Create a custom runtime host, as per Microsoft documentation
  2. Replace the init_fptr call (with the hostfxr_initialize_for_runtime_config signature) for hostfxr_initialize_for_dotnet_command_line
  3. Compile the C++ executable and put the self-contained executable alongside it
  4. Add COREHOST_TRACE=1 and COREHOST_TRACE_VERBOSITY=4 to environment variables for logging
  5. Launch the host app and observe missing .deps.json and hostpolicy.dll errors in console output.

Expected behavior

Call to hostfxr_initialize_for_dotnet_command_line to pass without issues (return code = 0, valid host context returned).

Actual behavior

Host context fails to initialize with error code 0x80008083, and following logs are displayed: (truncated = full path to both the SCD executable and native host executable)

--- Invoked hostfxr_initialize_for_dotnet_command_line [commit hash: 55fb7ef977e7d120dc12f0960edcff0739d7ee0e]
Checking if CoreCLR path exists=[C:\Program Files\dotnet\host\fxr\6.0.8\coreclr.dll]
--- Executing in muxer mode...
Using the provided arguments to determine the application to execute.
App runtimeconfig.json from [<truncated>\UE5InteropManaged.exe]
Runtime config is cfg=<truncated>\UE5InteropManaged.runtimeconfig.json dev=<truncated>\Internal_LocalDev\bin\UE5InteropManaged.runtimeconfig.dev.json
Attempting to read runtime config: <truncated>\UE5InteropManaged.runtimeconfig.json
Attempting to read dev runtime config: <truncated>\UE5InteropManaged.runtimeconfig.dev.json
Runtime config [<truncated>\UE5InteropManaged.runtimeconfig.json] is valid=[1]
Executing as a self-contained app as per config file [<truncated>\UE5InteropManaged.runtimeconfig.json]
--- Resolving hostpolicy.dll version from deps json [<truncated>\UE5InteropManaged.deps.json]
Cannot use file stream for [<truncated>\UE5InteropManaged.deps.json]: No such file or directory
The expected hostpolicy.dll directory is [C:\Program Files\dotnet\]
The hostpolicy.dll was not found in [C:\Program Files\dotnet\]
A fatal error was encountered. The library 'hostpolicy.dll' required to execute the application was not found in 'C:\Program Files\dotnet\'.
Failed to run as a self-contained app.
  - The application was run as a self-contained app because '<truncated>\UE5InteropManaged.runtimeconfig.json' was not found.
  - If this should be a framework-dependent app, add the '<truncated>\UE5InteropManaged.runtimeconfig.json' file and specify the appropriate framework.

Regression?

Not aware, haven't tested on previous versions of .NET.

Known Workarounds

Not aware (not using a self-contained distribution would not be ideal for the target use-case).

Configuration

.NET version: 6.0.8 OS: Windows 11 21H2 (22000.978) Architecture: x64 Is error specific to environment: not aware, haven't tested on Linux Using Blazor: no, the managed app is a standard console application

Other information

No response

コントリビューターガイド