Search code examples
c#dll.net-assembly

AssemblyLoaderHelper not resolving


My program has the ability to download new DLLs and restart itself as a self-updater. I'm trying to add some checks, like "before replacing this DLL, make sure it has class X and method Y".

I'm trying to use AssemblyLoaderHelper for this. My implementation matches other examples across the internet, seen here: https://gist.github.com/TsuyoshiUshio/29f930aa267ff8bea292715467b0f40a

To use it,

        var loadContext = new AssemblyLoaderHelper(dllDirectory);
        var assemblyName = AssemblyName.GetAssemblyName(dllFile);
        Assembly assembly = loadContext.LoadFromAssemblyName(assemblyName);

dllDirectory definitely exist, and dllFile is contained within it, but LoadFromAssemblyName() always returns null.

Am i doing something wrong? i could also ask, is there a better way to check a DLL for the existence of a class/method? I don't need to execute anything from the DLL. i can't use just Assemmbly.Load() because i already have another version loaded.

Thanks!


Solution

  • ok so turns out AssemblyDependencyResolver wants the path to a dll, not the dll's directory (so c:\plugins\myDll.dll NOT c:\plugins). seems weird since you can use this to load multiple DLLs, but whatever. it works!