October 29, 2012

Load an assembly from a network location


Error:
Exception Message: Could not load file or assembly 'file:///Z:\PROJECT\bin\Debug\XYZ.dll' or one of its dependencies. Operation is not supported. (Exception from HRESULT: 0x80131515)

Exception Message: 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.


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


Solution:
It will be solved if you add a simple magic ;-) line to YOURPROJECT.exe.config file 
- Open YOURPROJECT.exe.config file from bin folder
- Add <loadFromRemoteSources enabled="true" /> to <runtime> tag

2 comments:

Anonymous said...

The next time I read a blog, I hope that it doesnt disappoint me as much as this one. I mean, I know it was my choice to read, but I actually thought youd have something interesting to say. All I hear is a bunch of whining about something that you could fix if you werent too busy looking for attention.

Oleg Poole said...

I always find this security exception error during my .NET development work, but with the help of this code my problem is resolved.