Skip to content

Self-contained .net core 3.1 app giving hostxfr.dll not found (even though it is in the current directory) #43030

Description

@srothkin

Description

I have a win-x64 app which is C++ calling a C++/CLI .Net Core DLL which is in turn calling a C# .Net core 3.1 DLL (which in turn uses Microsoft.Data.SqlClient). It works fine on my development computer (in Visual Studio 2019). I copy the .exe and all of the DLLs (including runtime from dotnet publish selfcontained) to another machine (which doesn't have Visual Studio OR the .net core runtime installed). The exe crashes with hostxfr.dll not found even though it is in the current directory (alongside the exe).

Configuration

  • .Net Core 3.1
  • Build machine: Windows 10
  • Test machine: Windows Server 2012 R2 Datacenter
  • x64

Regression?

  • Unknown - first time trying this. Previous build of product was with Visual Studio 2015 and .Net Framework 4.5 and with all runtimes installed on machine rather than distributed with code.

Other information

I've setup the C++ exe and C++/CLI projects to copy all of the dependencies to the target directory and the C# project post build step has

dotnet restore -r win-x64
dotnet publish "$(ProjectFileName)" -r win-x64 --no-build -c $(ConfigurationName) -o $(OutDir) --no-restore -p:PublishReadyToRun=true --self-contained true

When I run it with set COREHOST_TRACE=1 I get

Can't open the SDK installed location registry key, result: 0x2
Using global installation location [C:\Program Files\dotnet] as runtime location
.
A fatal error occurred. The required library hostfxr.dll could not be found.
If this is a self-contained application, that library should exist in [].
If this is a framework-dependent application, install the runtime in the global
location [C:\Program Files\dotnet] or use the DOTNET_ROOT environment variable t
o specify the runtime location or register the runtime location in [HKLM\SOFTWAR
E\dotnet\Setup\InstalledVersions\x64\InstallLocation].

The .NET Core runtime can be found at:
  - https://aka.ms/dotnet-core-applaunch?missing_runtime=true&arch=x64&rid=win81
-x64
Failed to start the .NET Core runtime. Error code -2147450749

I tried setting DOTNET_ROOT=the target dir name -- that didn't help. I tried removing the ready-to-run flag and rebuilding - that didn't help either.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions