How to load a remote assembly using Assembly.Load

If you try to load a remote assembly using it’s path you’ll likely get a permission or operation exception.

When using LoadFrom:

Assembly a1 = Assembly.LoadFrom(file);

I got this error. Could not load file or assembly or one of its dependencies. Operation is not supported. (Exception from HRESULT: 0x80131515)

I figured I could copy it locally, but knew there must be a better way. So I scoured the interwebs and found this post on StackOverflow:

http://stackoverflow.com/questions/8308312/assembly-loaded-using-assembly-loadfrom-on-remote-machine-causes-securityexcep

Which basically tells us to use Assembly.Load instead of Assembly.LoadFrom. Here’s the code that works:

Assembly a2 = Assembly.Load(File.ReadAllBytes(file));

Jon

Share