Recently I was having trouble running sample projects made for Visual Studio 2010 and .NET4. When opening the solution I would get the following warning:
You should only open projects from a trustworthy source. The project file 'project' may have come from a location that isn’t fully trusted. It could represent a security risk by executing customer build steps when opened in Microsoft Visual Studio that could cause damage to your computer or compromise your private information.
I figured that this is a valid warning and continued opening the project. Upon the first build I was getting errors that didn’t seem right like missing assembly references or System.IO.FileLoadException. I would get different errors doing build then clean verses a rebuild. The System.IO.FileLoadException full error is:
System.IO.FileLoadException: Could not load file or assembly 'assemblyPath' or one of its dependencies. Operation is not supported. (Exception from HRESULT: 0x80131515 (COR_E_NOTSUPPORTED)) 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=131738 for more information.
Most references to this error explain how this is now the default for .NET 4 when loading a remote assembly but in my case this isn’t the problem since the assemblies I’m using are contained within the project.
Looking further I uncovered the problem was with Windows Blocked Files. When downloading the file from the internet (a zip file in my case), if I had looked at the Properties | General tab I would have seen the problem. This file came from another computer and might be blocked to help protect this computer. Also note this is only a problem with the NTFS file system.
So here are the various solutions depending on your current situation. Before extracting a file (ZIP, TAR, whatever) you can simply push the “Unblock” button before extracting the file and then all extracted files will be unblocked. If you already have multiple files that you do not want to bring up the properties on each you can copy the files to a FAT, FAT32 or exFAT file system then back to the original location. I used a USB Flash Drive formatted to exFAT to transfer the files back and forth. You can use your imagination here. I looked for a command line way to unblock files but I could not find one.
Just to make sure I was also owner of all these files I ran the following on the project in an administrative command prompt window:
takeown /F ‘project directory’ /R
After these steps all the errors during compiling went away.