Skip to content
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public void ActivateClass_ValidateIErrorInfoResult()
.Execute();

result.Should().Pass()
.And.HaveStdOutContaining($"The specified runtimeconfig.json [{missingRuntimeConfig}] does not exist");
.And.HaveStdOutContaining($"runtimeconfig.json [{missingRuntimeConfig}] does not exist");
}
}

Expand Down
5 changes: 3 additions & 2 deletions src/native/corehost/comhost/comhost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ namespace
delegates.delegate_no_load_cxt = nullptr;

get_function_pointer_fn get_function_pointer;
int status = load_fxr_and_get_delegate(
int status = load_fxr_and_get_delegate(
hostfxr_delegate_type::hdt_get_function_pointer,
[app_path](const pal::string_t& host_path, pal::string_t* config_path_out)
{
Expand Down Expand Up @@ -123,7 +123,8 @@ namespace
*load_context = nullptr; // Default context
}
},
reinterpret_cast<void**>(&get_function_pointer)
reinterpret_cast<void**>(&get_function_pointer),
false // do not ignore missing config file if there's an active context
);
if (status != StatusCode::Success)
return status;
Expand Down
51 changes: 31 additions & 20 deletions src/native/corehost/fxr_resolver.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace fxr_resolver
}

template<typename THostPathToConfigCallback, typename TBeforeRunCallback>
int load_fxr_and_get_delegate(hostfxr_delegate_type type, THostPathToConfigCallback host_path_to_config_path, TBeforeRunCallback on_before_run, void** delegate)
int load_fxr_and_get_delegate(hostfxr_delegate_type type, THostPathToConfigCallback host_path_to_config_path, TBeforeRunCallback on_before_run, void** delegate, bool try_ignore_missing_config)
{
pal::dll_t fxr;

Expand Down Expand Up @@ -67,34 +67,45 @@ int load_fxr_and_get_delegate(hostfxr_delegate_type type, THostPathToConfigCallb
if (status != StatusCode::Success)
return status;

hostfxr_initialize_parameters parameters {
sizeof(hostfxr_initialize_parameters),
host_path.c_str(),
dotnet_root.c_str()
};

hostfxr_set_error_writer_fn set_error_writer_fn = reinterpret_cast<hostfxr_set_error_writer_fn>(pal::get_symbol(fxr, "hostfxr_set_error_writer"));

{
propagate_error_writer_t propagate_error_writer_to_hostfxr(set_error_writer_fn);
if (!try_ignore_missing_config || pal::file_exists(config_path))
{
hostfxr_initialize_parameters parameters {
sizeof(hostfxr_initialize_parameters),
host_path.c_str(),
dotnet_root.c_str()
};

hostfxr_handle context;
int rc = hostfxr_initialize_for_runtime_config(config_path.c_str(), &parameters, &context);
if (!STATUS_CODE_SUCCEEDED(rc))
return rc;
hostfxr_handle context;
int rc = hostfxr_initialize_for_runtime_config(config_path.c_str(), &parameters, &context);
if (!STATUS_CODE_SUCCEEDED(rc))
return rc;

on_before_run(fxr, context);

on_before_run(fxr, context);
rc = hostfxr_get_runtime_delegate(context, type, delegate);

rc = hostfxr_get_runtime_delegate(context, type, delegate);
int rcClose = hostfxr_close(context);
if (rcClose != StatusCode::Success)
{
assert(false && "Failed to close host context");
trace::verbose(_X("Failed to close host context: 0x%x"), rcClose);
}

int rcClose = hostfxr_close(context);
if (rcClose != StatusCode::Success)
return rc;
}
else
{
assert(false && "Failed to close host context");
trace::verbose(_X("Failed to close host context: 0x%x"), rcClose);
// null context means use the current one, if none exists it will fail
int rc = hostfxr_get_runtime_delegate(nullptr, type, delegate);
if (rc == StatusCode::HostInvalidState)
{
trace::error(_X("Expected active runtime context because runtimeconfig.json [%s] does not exist."), config_path.c_str());
}
return rc;
}

return rc;
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/native/corehost/ijwhost/ijwhost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ pal::hresult_t get_load_in_memory_assembly_delegate(pal::dll_t handle, load_in_m
return StatusCode::Success;
},
[](pal::dll_t fxr, hostfxr_handle context){ },
reinterpret_cast<void**>(&get_function_pointer)
reinterpret_cast<void**>(&get_function_pointer),
true // ignore missing config file if there's an active context
);
if (status != StatusCode::Success)
return status;
Expand Down