Jon Gallant

How to load a remote assembly using Assembly.Load

1 min read

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);
```python
I got this error. Could not load file or assembly or one of its dependencies. Operation is not supported. (Exception from HRESULT: 0x80131515)
![5126.image 5F00 thumb 5F00 2C51C4A6](/images/blog/5126.image_5F00_thumb_5F00_2C51C4A6.png)
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:
[https://stackoverflow.com/questions/8308312/assembly-loaded-using-assembly-loadfrom-on-remote-machine-causes-securityexcep](https://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. Heres the code that works:
```csharp
Assembly a2 = Assembly.Load(File.ReadAllBytes(file));

Jon

Share:
Share on X