-
Notifications
You must be signed in to change notification settings - Fork 153
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
Problem loading unmanaged assemblies #1253
Comments
@cw397 Would you please try running with version 3.16.0-dev00076, available from our MyGet feed? |
That version doesn't seem to help I'm afraid, I still get the same behaviour. |
@cw397 Thanks... I had made substantial changes to how dependencies are analyzed but I guess unmanaged dependencies still need to be addressed. |
I've been able to work around this issue by using a SetUpFixture as follows: [SetUpFixture, Order(1)] // Order doesn't work, so it has to be in a namespace higher than other namespaces if other setup fixtures depend on unmanaged dlls
public class SetUpUnmanagedAssembliesResolving
{
private AssemblyDependencyResolver runtimeResolver;
[OneTimeSetUp]
public void SetupAssemblyLoadContextToHandleUnmanagedAssemblyLoadFailure()
{
var assembly = typeof(SetUpUnmanagedAssembliesResolving).Assembly;
var testAssemblyLoadContext = AssemblyLoadContext.GetLoadContext(assembly) ?? AssemblyLoadContext.Default;
testAssemblyLoadContext.ResolvingUnmanagedDll += OnResolvingUnmanagedDll;
var assemblyLocation = assembly.Location;
runtimeResolver = new AssemblyDependencyResolver(assemblyLocation);
}
private IntPtr OnResolvingUnmanagedDll(Assembly requestingAssembly, string dllName)
{
var path = runtimeResolver.ResolveUnmanagedDllToPath(dllName);
if (!string.IsNullOrEmpty(path))
{
return NativeLibrary.Load(path);
}
return IntPtr.Zero;
}
} |
I'm working on a fix for this. |
Loading of unmanaged assemblies suffers from the same issues as loading managed assemblies in that the wrong deps.json is used by default. This updates the TestAssemblyLoadContext to use the exact same pattern for loading unmanaged assemblies as managed assemblies. 1. Use the default assembly loading logic (I'm unsure if we actually need this since, in both managed and unmanaged, the base AssemblyLoadContext logic is a no-op and it's actually the VM that has some logic for loading assemblies). 2. Use an AssemblyDependencyResolver for the test assembly. 3. Check in the same folder as the test assembly (in case the dependencies are not fully specified in deps.json). Resolves nunit#1253
I have exactly this issue and would just like to add my details here to maybe make this more discoverable for future readers. We are using Running from within VS or with
Adding the workaround code posted by #1253 (comment) above does work 💯 Obvioulsy, having #1317 make it into production will be ideal, but I fear I'll have to live with the workaround for now. |
Loading of unmanaged assemblies suffers from the same issues as loading managed assemblies in that the wrong deps.json is used by default. This updates the TestAssemblyLoadContext to use the exact same pattern for loading unmanaged assemblies as managed assemblies. 1. Use the default assembly loading logic (I'm unsure if we actually need this since, in both managed and unmanaged, the base AssemblyLoadContext logic is a no-op and it's actually the VM that has some logic for loading assemblies). 2. Use an AssemblyDependencyResolver for the test assembly. 3. Check in the same folder as the test assembly (in case the dependencies are not fully specified in deps.json). Resolves nunit#1253
Loading of unmanaged assemblies suffers from the same issues as loading managed assemblies in that the wrong deps.json is used by default. This updates the TestAssemblyLoadContext to use the exact same pattern for loading unmanaged assemblies as managed assemblies. 1. Use the default assembly loading logic (I'm unsure if we actually need this since, in both managed and unmanaged, the base AssemblyLoadContext logic is a no-op and it's actually the VM that has some logic for loading assemblies). 2. Use an AssemblyDependencyResolver for the test assembly. 3. Check in the same folder as the test assembly (in case the dependencies are not fully specified in deps.json). Resolves nunit#1253
Issue #1208 became a sort of anthology of somewhat related problems, leading (me) to a certain amount of confusion. All issues are solved, except the one described in this comment by @cw397. I'm making this problem a separate issue. The extract below gives the original description of the problem.
Our issue is with an unmanaged/native library. We are using a NuGet package (Esri.ArcGISRuntime) that has some unmanaged dependencies. As seems to be the convention, these get copied to a runtimes/{rid}/native folder within our test project bin/Debug directory, e.g. runtimes/win-x64/native. As with all the other issues, tests that use this library run fine in Visual Studio but fail with the error "Could not load ArcGIS Runtime (RuntimeCoreNet100_15.dll) or one of its dependencies" when run with NUnit Console.
I can workaround the issue in a couple of ways:
I have found some explanation about how native assemblies are probed for (https://learn.microsoft.com/en-us/dotnet/core/dependency-loading/default-probing), and potential ways of configuring it (https://github.com/dotnet/cli/blob/master/Documentation/specs/runtime-configuration-file.md), however I haven't been able to figure out any better workarounds than the two listed above.
The text was updated successfully, but these errors were encountered: