17

I am trying to load assembly by :

Assembly component = Assembly.LoadFrom(componentPath);

where componentPath is a full path of network location and get the the following error:

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.

If this load is not intended to sandbox the assembly, please enable the loadFromRemoteSources switch.See http://go.microsoft.com/fwlink/?LinkId=155569 for more information.

Can you please explan what should i do to avoid this security check ?

Thank You

Sam Axe
  • 33,313
  • 9
  • 55
  • 89
Sergey Kucher
  • 4,140
  • 5
  • 29
  • 47

3 Answers3

19

I was having this same issue. The reason was that the Assembly file was blocked by Windows. I resolved it by right clicking on the Assembly file and selecting properties. In the Properties dialog, click Unblock button under the General tab and click Apply and then OK.

Reference: http://blogs.msdn.com/b/drew/archive/2009/12/24/xunit-and-td-net-fixing-the-attempt-was-made-to-load-an-assembly-from-a-network-location-problem.aspx

Furqan Safdar
  • 16,260
  • 13
  • 59
  • 93
8

In addition to Furqan Safdar's answer, another option would be to add this tag in the configuration file:

<configuration>
   <runtime>
      <loadFromRemoteSources enabled="true"/>
   </runtime>
</configuration>

Hope these links could help:

http://msdn.microsoft.com/en-us/library/dd409252(VS.100).aspx

Community
  • 1
  • 1
Starnuto di topo
  • 3,215
  • 5
  • 32
  • 66
5

Read Best Practices for Assembly Loading to get an idea.
Also read this msdn blog on .NET Security

Saurabh Gokhale
  • 53,625
  • 36
  • 139
  • 164