One way is to read the bytes of the file and use Assembly.Load overload, which takes an array of bytes, similar to what you do in your second example. I'm not sure System.IO.GetBytes , but try File.ReadAllBytes instead.
byte[] assemblyBytes = File.ReadAllBytes("asm-path"); var assembly = Assembly.Load(assemblyBytes);
However, this may not be enough depending on what you want to do, because you cannot unload the assembly after it is loaded. To get around this, if you need to, you can load the assembly into your AppDomain and then unload the AppDomain as soon as you are done with it.
AppDomain ad = AppDomain.CreateDomain("New_Assembly_AD"); byte[] assemblyBytes = File.ReadAllBytes("asm-path"); var assembly = ad.Load(assemblyBytes);
Once you are done with the assembly object, you can unload the AppDomain.
AppDomain.Unload(ad);
source share