47

.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?

6 Answers 6

101

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

1
  • 4
    I was unblocking files individually. Once I did it from the ZIP instead everything worked great. Thank you.
    – Xcalibur37
    Commented May 21, 2016 at 16:17
10

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.

3

To find the problematic assembly, use fuslogvw (part of Windows SDK and therefore installed with every Visual Studio).

To fix the problem, you, actually, have to add loadFromRemoteSources element to the your application configuration file. Are you sure that you've added loadFromRemoteSources inside of <runtime> element?

Alternatively, you can upgrade to .NET 4.5, because as MSDN says:

In the .NET Framework 4.5, assemblies on local network shares are run as full trust by default; you do not have to enable the element

1

The easiest way to fix the problem in a cmd.exe prompt is:

type problem.dll > no.problem.dll

You can check for alternate streams with:

dir /r problem.dll

The problematic ones will show something like:

problem.dll:Zone.Identifier:$DATA
0

If anyone is having trouble even when unblocking try this.

My scenario was that I have a folder shared on the network where I put the zip with DLL-files. Accessed it from the server that's supposed to use the dll. If I unpacked the zip from the server it wouldn't work even when unblocking. What worked for me was unpacking the zip on the source computer and just copying all the files instead of the zip file. I'm not sure why it works though.

Maybe my account is more trusted than the source of the zip file.

0

This happened to a colleague of mine today. I sent a zipped file of the software we built, and after unzipping the file, this exception would be thrown rightaway.

The solution was to unzip the file using 7-Zip instead of the built-in Windows zip extractor (which I presume attached some security attributes to extracted items).

Not the answer you're looking for? Browse other questions tagged or ask your own question.