Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

an attempt was made to load an assembly from a network location which would have caused the assembly to be sandboxed

Tags:

.net

c#-4.0

.Net 4.0 : Getting error

an attempt was made to load an assembly from a network location which would have caused the assembly to be sandboxed

applied setting

<loadFromRemoteSources enabled="true"/> 

didn't help. How can i get to know which assembly is causing problem? How can i resolve it?

like image 422
krishan aggarwal Avatar asked Aug 02 '13 11:08

krishan aggarwal


People also ask

Which would have caused the assembly to be sandboxed in previous versions of the .NET framework?

NotSupportedException: An attempt was made to load an assembly from a network location which would have caused the assembly to be sandboxed in previous versions of the . NET Framework. This release of the . NET Framework does not enable CAS policy by default, so this load may be dangerous.

Can not load file or assembly?

In summary if you get the "Could not load file or assembly error", this means that either your projects or their references were built with a reference to a specific version of an assembly which is missing from your bin directory or GAC.


2 Answers

I have also ran into this issue, but my problem occurred because the file had been blocked since it was downloaded from an unsecured source, GMail in my case. I solved it by

  1. Right Click problematic file
  2. Click Properties
  3. Click Unblock

In my case it was the entire .zip file that was unsafe, so I unblocked the file before I unzipped it.

More on this solution here and here

like image 184
Barry Tormey Avatar answered Oct 20 '22 21:10

Barry Tormey


I've seen this where the "network location" is mentioned and you are using a DLL locally (i.e. not remotely) - but it was copied from a remote location (e.g. internet file share site).

The trick in this case was I suspected the DLL was blocked due to the streams concept, but the explorer UI properties dialog did not show the "unblock" button.

To work around this, I used the sysinternals tool "streams" (found here: Streams download) like so:

streams <your dll> -> view stream streams -d <your dll> -> delete the stream data on a file 

There's also a recurse option with -r if you want to target a group of files.

I hope this helps someone else - it was tricky because the UI didn't show it was blocked, but it clearly was (perhaps due to some other security measure here).

This solution also means you don't need to adjust the loadFromRemoteSources flag, as that is quite a broad stroke.

like image 42
Justin C Avatar answered Oct 20 '22 21:10

Justin C