Skip to content

Commit

Permalink
Fix HostApiInvokerApp setting DllImportResolver for hostfxr (#108954)
Browse files Browse the repository at this point in the history
The test wasn't saving the modified runtime config, so the app didn't actually set the DllImportResolver. The app was also using the incorrect path in its implementation. Whether or not it is needed for the test to run properly is dependent on the platform (and how it handles trying to load an already loaded native binary). I found this when trying to run the host tests on linux-musl-x64.
  • Loading branch information
elinor-fung authored Oct 17, 2024
1 parent d8aadb1 commit 43813ac
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,11 @@ public static void MainCore(string[] args)

if (hostfxrPath is not null)
{
Console.WriteLine($"Registering DLLImportResolver for {nameof(HostFXR.hostfxr)} -> {hostfxrPath}");
NativeLibrary.SetDllImportResolver(typeof(Program).Assembly, (libraryName, assembly, searchPath) =>
{
return libraryName == nameof(HostFXR.hostfxr)
? NativeLibrary.Load(libraryName, assembly, searchPath)
? NativeLibrary.Load(hostfxrPath, assembly, searchPath)
: default;
});
}
Expand Down
3 changes: 2 additions & 1 deletion src/installer/tests/HostActivation.Tests/NativeHostApis.cs
Original file line number Diff line number Diff line change
Expand Up @@ -782,7 +782,8 @@ public SharedTestState()
// paths to hostfxr so that it can handle resolving the library.
RuntimeConfig.FromFile(HostApiInvokerApp.RuntimeConfigJson)
.WithProperty("HOSTFXR_PATH", TestContext.BuiltDotNet.GreatestVersionHostFxrFilePath)
.WithProperty("HOSTFXR_PATH_TEST_BEHAVIOR", TestBehaviorEnabledDotNet.GreatestVersionHostFxrFilePath);
.WithProperty("HOSTFXR_PATH_TEST_BEHAVIOR", TestBehaviorEnabledDotNet.GreatestVersionHostFxrFilePath)
.Save();

SdkAndFrameworkFixture = new SdkAndFrameworkFixture();
}
Expand Down

0 comments on commit 43813ac

Please sign in to comment.