I am able to load the dll using this form -
System.Reflection.Assembly assembly =
System.Reflection.Assembly.LoadFile(@\"C:\\Users\\amit.pandey\\Documents\\
Alternatively, loading the file from disk and calling Assembly.Load
on the byte array seems to work (Framework 4):
string Share = @"R:\Test\TestAssembly.dll";
byte[] AssmBytes = File.ReadAllBytes(Share);
Assembly a = Assembly.Load(AssmBytes);
//Invoking a method from the loaded assembly
var obj = a.CreateInstance("TestAssembly.Class1");
obj.GetType().InvokeMember("HelloWorld", BindingFlags.InvokeMethod, null, obj, null);
Since MS blocks network loading in LoadFrom()
, it would indicate that doing so is probably not best practices. However, this is similar to the process that is often used with embedding assemblies as resources in an EXE.
You need to tell the machine to trust that location.
You can do this with the caspol utility.
Instead of loading the binary content you can use Assembly.UnsafeLoadFrom. See http://msdn.microsoft.com/en-us/library/system.reflection.assembly.unsafeloadfrom%28v=vs.110%29.aspx
This worked fine for me in all purposes.