jeudi 16 juin 2022

C# Assembly loaded in one class, throws an exception in another

I have a very weird situation here:

internal class Loader {
    internal void Load() {
        UseAssembly();
    }
    
    private void UseAssembly() {
        var marshaller = new Marshaller();
        Assembly assembly = marshaller.LoadAssembly();
    }
}

[Serializable]
public class Marshaller {
    internal Assembly LoadAssembly() {
        return Assembly.ReflectionOnlyLoadFrom("C:\\Users\\OLNO\\Downloads\\SkinProject1.dll");
    }
}

Now here is the interesting part:

enter image description here

It is interesting, because the file exists in that location, and because the exception itself is thrown at this line:

Assembly assembly = marshaller.LoadAssembly();

but not this one:

Assembly assembly = Assembly.ReflectionOnlyLoadFrom("C:\\Users\\OLNO\\Downloads\\SkinProject1.dll"

and when instead of code above I have this one, it works just fine:

internal class Loader {
    internal void Load() {
        UseAssembly();
    }
    
    private void UseAssembly() {
        Assembly assembly = Assembly.ReflectionOnlyLoadFrom("C:\\Users\\OLNO\\Downloads\\SkinProject1.dll");
    }
}

I'm working in Visual Studio 2019, and I've tried cleaning the build and rebuilding the solution. This issue looks pretty much like magic to me... How do I fix this?

Thanks in advance.





Aucun commentaire:

Enregistrer un commentaire