Skip to content

Commit

Permalink
AssemblyLoader should use absolute assembly path when loading assembl…
Browse files Browse the repository at this point in the history
…ies (#570)
  • Loading branch information
suhsteve authored Jun 27, 2020
1 parent 3106e8e commit 886cec0
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
26 changes: 26 additions & 0 deletions src/csharp/Microsoft.Spark.UnitTest/AssemblyLoaderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,25 @@

using System;
using System.IO;
using System.Reflection;
using System.Runtime.Loader;
using Microsoft.Spark.Interop.Ipc;
using Microsoft.Spark.Utils;
using Moq;
using Xunit;

namespace Microsoft.Spark.UnitTest
{
[Collection("Spark Unit Tests")]
public class AssemblyLoaderTests
{
private readonly Mock<IJvmBridge> _mockJvm;

public AssemblyLoaderTests(SparkFixture _fixture)
{
_mockJvm = _fixture.MockJvm;
}

[Fact]
public void TestAssemblySearchPathResolver()
{
Expand Down Expand Up @@ -45,5 +56,20 @@ public void TestAssemblySearchPathResolver()
AssemblySearchPathResolver.AssemblySearchPathsEnvVarName,
null);
}

[Fact]
public void TestResolveAssemblyWithRelativePath()
{
_mockJvm.Setup(m => m.CallStaticJavaMethod(
"org.apache.spark.SparkFiles",
"getRootDirectory"))
.Returns(".");

AssemblyLoader.LoadFromFile = AssemblyLoadContext.Default.LoadFromAssemblyPath;
Assembly expectedAssembly = Assembly.GetExecutingAssembly();
Assembly actualAssembly = AssemblyLoader.ResolveAssembly(expectedAssembly.FullName);

Assert.Equal(expectedAssembly, actualAssembly);
}
}
}
6 changes: 3 additions & 3 deletions src/csharp/Microsoft.Spark/Utils/AssemblyLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -189,12 +189,12 @@ private static bool TryLoadAssembly(string assemblyFileName, ref Assembly assemb
{
foreach (string searchPath in s_searchPaths.Value)
{
string assemblyPath = Path.Combine(searchPath, assemblyFileName);
if (File.Exists(assemblyPath))
var assemblyFile = new FileInfo(Path.Combine(searchPath, assemblyFileName));
if (assemblyFile.Exists)
{
try
{
assembly = LoadFromFile(assemblyPath);
assembly = LoadFromFile(assemblyFile.FullName);
return true;
}
catch (Exception ex) when (
Expand Down

0 comments on commit 886cec0

Please sign in to comment.