Skip to content

Commit

Permalink
Fix DependencyContext splitting on semi-colon (#87518)
Browse files Browse the repository at this point in the history
* Fix DependencyContext splitting on semi-colon

5e67657 introduced a bug in DependencyContextPaths where the static array is not initialized before it is being used in the Create static method.

This fix removes the static array since it is only used once.

- Don't cache the semicolon array since it is only used once at startup
- Skip test on netfx since it doesn't work.
  • Loading branch information
eerhardt committed Jun 14, 2023
1 parent 8042fac commit 8b7c300
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
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)
{
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()
{
// 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

0 comments on commit 8b7c300

Please sign in to comment.