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:

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));