{
pal::string_t fxr_dir;
#if defined(FEATURE_APPHOST) || defined(FEATURE_LIBHOST)
+ // For apphost and libhost, root_path is expected to be a directory.
+ // For libhost, it may be empty if app-local search is not desired (e.g. com/ijw/winrt hosts, nethost when no assembly path is specified)
// If a hostfxr exists in root_path, then assume self-contained.
if (root_path.length() > 0 && library_exists_in_dir(root_path, LIBFXR_NAME, out_fxr_path))
{
return false;
}
#else // !FEATURE_APPHOST && !FEATURE_LIBHOST
+ // For non-apphost and non-libhost (i.e. muxer), root_path is expected to be the full path to the host
pal::string_t host_dir;
host_dir.assign(get_directory(root_path));
return;
}
- var fixture = sharedState.ComLibraryFixture
- .Copy();
-
string scenario = synchronous ? "synchronous" : "concurrent";
string args = $"comhost {scenario} {count} {sharedState.ComHostPath} {sharedState.ClsidString}";
CommandResult result = Command.Create(sharedState.NativeHostPath, args)
.CaptureStdErr()
.CaptureStdOut()
.EnvironmentVariable("COREHOST_TRACE", "1")
- .EnvironmentVariable("DOTNET_ROOT", fixture.BuiltDotnet.BinPath)
- .EnvironmentVariable("DOTNET_ROOT(x86)", fixture.BuiltDotnet.BinPath)
+ .EnvironmentVariable("DOTNET_ROOT", sharedState.ComLibraryFixture.BuiltDotnet.BinPath)
+ .EnvironmentVariable("DOTNET_ROOT(x86)", sharedState.ComLibraryFixture.BuiltDotnet.BinPath)
.Execute();
result.Should().Pass()
}
}
+ [Fact]
+ public void ActivateClass_IgnoreAppLocalHostFxr()
+ {
+ if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
+ {
+ // COM activation is only supported on Windows
+ return;
+ }
+
+ var fixture = sharedState.ComLibraryFixture.Copy();
+
+ File.WriteAllText(Path.Combine(fixture.TestProject.BuiltApp.Location, "hostfxr.dll"), string.Empty);
+ var comHostWithAppLocalFxr = Path.Combine(
+ fixture.TestProject.BuiltApp.Location,
+ $"{ fixture.TestProject.AssemblyName }.comhost.dll");
+
+ string args = $"comhost synchronous 1 {comHostWithAppLocalFxr} {sharedState.ClsidString}";
+ CommandResult result = Command.Create(sharedState.NativeHostPath, args)
+ .CaptureStdErr()
+ .CaptureStdOut()
+ .EnvironmentVariable("COREHOST_TRACE", "1")
+ .EnvironmentVariable("DOTNET_ROOT", fixture.BuiltDotnet.BinPath)
+ .EnvironmentVariable("DOTNET_ROOT(x86)", fixture.BuiltDotnet.BinPath)
+ .Execute();
+
+ result.Should().Pass()
+ .And.HaveStdOutContaining("New instance of Server created")
+ .And.HaveStdOutContaining($"Activation of {sharedState.ClsidString} succeeded.")
+ .And.HaveStdErrContaining("Using environment variable DOTNET_ROOT");
+ }
+
public class SharedTestState : SharedTestStateBase
{
public string ComHostPath { get; }