Wednesday, May 12, 2010


With VS2010 adding references to your application from a network drive such as nLog can result in this error;

Could not load file or assembly 'NLog, Version=, Culture=neutral, PublicKeyToken=5120e14c03d0593c' or one of its dependencies. Operation is not supported. (Exception from HRESULT: 0x80131515)

This is a result of the default loadFromRemoteSources behavior of VS2010.  This directive specifies whether assemblies from remote sources should be granted full trust.
In the .NET Framework version 3.5 and earlier versions, if you loaded an assembly from a remote location, the assembly would run partially trusted with a grant set that depended on the zone in which it was loaded. For example, if you loaded an assembly from a Web site, it was loaded into the Internet zone and granted the Internet permission set. In other words, it executed in an Internet sandbox. If you try to run that assembly in the .NET Framework version 4, an exception is thrown; you must either explicitly create a sandbox for the assembly, or run it in full trust.

The <loadFromRemoteSources> element lets you specify that the assemblies that run partially trusted in earlier versions of the .NET Framework should be run fully trusted in the .NET Framework 4.
Adding the following to your app.config and C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE\devenv.exe.config will resolve the issue;

    <loadFromRemoteSources enabled="true"/>


Anonymous said...

Kind of a draconian solution there. Better to just right click the offending assembly, goto 'Properties', then 'Unblock'.

Anonymous said...

That doesn't work when the assembly is updated as it often is as a shared file. You would have to keep unlocking the file....