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

Fix DependencyContext splitting on semi-colon #87518

Merged
merged 3 commits into from
Jun 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ internal sealed class DependencyContextPaths

public IEnumerable<string> NonApplicationPaths { get; }

private static readonly char[] s_semicolon = new[] { ';' };

public DependencyContextPaths(
string? application,
string? sharedRuntime,
Expand All @@ -42,7 +40,13 @@ private static DependencyContextPaths GetCurrent()

internal static DependencyContextPaths Create(string? depsFiles, string? sharedRuntime)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this be private?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, unit tests use it through IVT. They could be refactored to use reflection instead, but I'm trying to get this through to unblock code flow - see dotnet/installer#16621 (comment).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh IVT, how you mock me.

{
string[]? files = depsFiles?.Split(s_semicolon, StringSplitOptions.RemoveEmptyEntries);
#if NETCOREAPP
const char separator = ';';
#else
// This method is only executed once at startup. No need to cache the char[].
char[] separator = { ';' };
#endif
string[]? files = depsFiles?.Split(separator, StringSplitOptions.RemoveEmptyEntries);
string? application = files != null && files.Length > 0 ? files[0] : null;

string[]? nonApplicationPaths = files?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,19 @@ public void MergeMergesRuntimeGraph()
Subject.Fallbacks.Should().BeEquivalentTo("win7-x64", "win7-x86");
}

[Fact]
[SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework, "GetEntryAssembly() returns null")]
public void DefaultWorksCorrectly()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@eerhardt this also fails on NativeAOT on runtime-extra-platforms:

Assert.NotNull() Failure

Stack trace
   at Microsoft.Extensions.DependencyModel.Tests.DependencyContextTests.DefaultWorksCorrectly() + 0x76
   at Microsoft.Extensions.DependencyModel.Tests!<BaseAddress>+0x1292ea4
   at System.Reflection.DynamicInvokeInfo.Invoke(Object, IntPtr, Object[], BinderBundle, Boolean) + 0xe6

GetEntryAssembly() does work on NativeAOT though

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixing in #87666.

{
// only need to assert the context contains non-null properties.

var context = DependencyContext.Default;
Assert.NotNull(context);
Assert.NotNull(context.RuntimeGraph);
Assert.NotNull(context.RuntimeLibraries);
Assert.NotNull(context.Target);
}

private TargetInfo CreateTargetInfo()
{
return new TargetInfo(
Expand Down