Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fxr] Use std::find_if when searching for root framework. #72080

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,11 @@ public void TwoAppFrameworksOnTopOfMiddleWare()
.WithFramework("OMWare", "7.3.1"))
// https://github.com/dotnet/runtime/issues/71027
// This should pass just fine and resolve all frameworks correctly
// Currently it fails because it does resolve frameworks, but incorrectly
// looks for hostpolicy in MiddleWare, instead of Microsoft.NETCore.App.
.Should().Fail().And.HaveStdErrContaining("hostpolicy");
//.ShouldHaveResolvedFramework(
// MicrosoftNETCoreApp, "5.1.1")
//.And.HaveResolvedFramework("MiddleWare", "2.1.")
//.And.HaveResolvedFramework("SerializerWare", "3.0.1")
//.And.HaveResolvedFramework("OMWare", "7.3.1");
.ShouldHaveResolvedFramework(
MicrosoftNETCoreApp, "5.1.1")
.And.HaveResolvedFramework("MiddleWare", "2.1.")
.And.HaveResolvedFramework("SerializerWare", "3.0.1")
.And.HaveResolvedFramework("OMWare", "7.3.1");
}

private CommandResult RunTest(
Expand Down
15 changes: 14 additions & 1 deletion src/native/corehost/fx_definition.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,20 @@ typedef std::vector<std::unique_ptr<fx_definition_t>> fx_definition_vector_t;

static const fx_definition_t& get_root_framework(const fx_definition_vector_t& fx_definitions)
{
return *fx_definitions[fx_definitions.size() - 1];
// Fixes https://github.com/dotnet/runtime/issues/71027.
// If this was to assume that Microsoft.NETCore.App is last in the runtimeconfig.json list
// then it could fail when users install frameworks that depends on other frameworks than
// just the root framework making the host incorrectly think that is the root framework
// and goes about loading hostpolicy in the wrong framework directory instead of the actual
// root framework. As such std::find_if is our friend here.
auto const& fx = std::find_if(
fx_definitions.begin(),
fx_definitions.end(),
[&](const std::unique_ptr<fx_definition_t>& fxdef)
{
return fxdef->get_name() == _X("Microsoft.NETCore.App");
});
return **fx;
}

static const fx_definition_t& get_app(const fx_definition_vector_t& fx_definitions)
Expand Down