Skip to content

Commit e943786

Browse files
committed
Skip the extension scan when the host assembly has no location
In an Android Release build the engine is packed inside the APK, so its Assembly.Location is empty. FindExtensionAssemblies passed Path.GetDirectoryName("") (null) to Path.Combine, which threw ArgumentNullException before any test could run (#1966). An assembly that is not a file has no folders around it to search, so the scan now returns early.
1 parent 2a2f8f7 commit e943786

2 files changed

Lines changed: 22 additions & 0 deletions

File tree

‎src/NUnitEngine/nunit.engine.core.tests/Services/ExtensionManagerTests.cs‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,20 @@ public void DisabledExtensionMayBeEnabled()
151151
.And.Property(nameof(ExtensionNode.Enabled)).True);
152152
}
153153

154+
[Test]
155+
public void FindExtensionAssemblies_HostAssemblyHasNoLocation()
156+
{
157+
// On Android, Release builds pack assemblies inside the APK, so the engine
158+
// has no Location. An assembly loaded from bytes is the same on desktop.
159+
var bytes = File.ReadAllBytes(Path.Combine(THIS_ASSEMBLY_DIRECTORY, "mock-assembly.dll"));
160+
var hostAssembly = Assembly.Load(bytes);
161+
Assume.That(hostAssembly.Location, Is.Empty);
162+
163+
var manager = new ExtensionManager();
164+
165+
Assert.That(() => manager.FindExtensionAssemblies(hostAssembly), Throws.Nothing);
166+
}
167+
154168
[Test]
155169
public void SkipsGracefullyLoadingOtherFrameworkExtensionAssembly()
156170
{

‎src/NUnitEngine/nunit.engine.core/Services/ExtensionManager.cs‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,14 @@ public void FindExtensionAssemblies(Assembly hostAssembly)
165165
{
166166
log.Info($"FindExtensionAssemblies called for host {hostAssembly.FullName}");
167167

168+
// An assembly that was not loaded from a file, such as one packed inside an
169+
// Android APK, has no folders around it to search for extensions.
170+
if (string.IsNullOrEmpty(hostAssembly.Location))
171+
{
172+
log.Info(" Host assembly has no location, so there are no extension directories to search");
173+
return;
174+
}
175+
168176
bool isChocolateyPackage = System.IO.File.Exists(Path.Combine(Path.GetDirectoryName(hostAssembly.Location)!, "VERIFICATION.txt"));
169177
string[] extensionPatterns = isChocolateyPackage
170178
? new[] { "nunit-extension-*/**/tools/", "nunit-extension-*/**/tools/*/" }

0 commit comments

Comments
 (0)