Skip to content

Commit 886cec0

Browse files
authored
AssemblyLoader should use absolute assembly path when loading assemblies (#570)
1 parent 3106e8e commit 886cec0

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed

src/csharp/Microsoft.Spark.UnitTest/AssemblyLoaderTests.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,25 @@
44

55
using System;
66
using System.IO;
7+
using System.Reflection;
8+
using System.Runtime.Loader;
9+
using Microsoft.Spark.Interop.Ipc;
710
using Microsoft.Spark.Utils;
11+
using Moq;
812
using Xunit;
913

1014
namespace Microsoft.Spark.UnitTest
1115
{
1216
[Collection("Spark Unit Tests")]
1317
public class AssemblyLoaderTests
1418
{
19+
private readonly Mock<IJvmBridge> _mockJvm;
20+
21+
public AssemblyLoaderTests(SparkFixture _fixture)
22+
{
23+
_mockJvm = _fixture.MockJvm;
24+
}
25+
1526
[Fact]
1627
public void TestAssemblySearchPathResolver()
1728
{
@@ -45,5 +56,20 @@ public void TestAssemblySearchPathResolver()
4556
AssemblySearchPathResolver.AssemblySearchPathsEnvVarName,
4657
null);
4758
}
59+
60+
[Fact]
61+
public void TestResolveAssemblyWithRelativePath()
62+
{
63+
_mockJvm.Setup(m => m.CallStaticJavaMethod(
64+
"org.apache.spark.SparkFiles",
65+
"getRootDirectory"))
66+
.Returns(".");
67+
68+
AssemblyLoader.LoadFromFile = AssemblyLoadContext.Default.LoadFromAssemblyPath;
69+
Assembly expectedAssembly = Assembly.GetExecutingAssembly();
70+
Assembly actualAssembly = AssemblyLoader.ResolveAssembly(expectedAssembly.FullName);
71+
72+
Assert.Equal(expectedAssembly, actualAssembly);
73+
}
4874
}
4975
}

src/csharp/Microsoft.Spark/Utils/AssemblyLoader.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -189,12 +189,12 @@ private static bool TryLoadAssembly(string assemblyFileName, ref Assembly assemb
189189
{
190190
foreach (string searchPath in s_searchPaths.Value)
191191
{
192-
string assemblyPath = Path.Combine(searchPath, assemblyFileName);
193-
if (File.Exists(assemblyPath))
192+
var assemblyFile = new FileInfo(Path.Combine(searchPath, assemblyFileName));
193+
if (assemblyFile.Exists)
194194
{
195195
try
196196
{
197-
assembly = LoadFromFile(assemblyPath);
197+
assembly = LoadFromFile(assemblyFile.FullName);
198198
return true;
199199
}
200200
catch (Exception ex) when (

0 commit comments

Comments
 (0)