xUnit and TD.Net: Fixing the “attempt was made to load an assembly from a network location” problem
I just started my first personal project using Visual Studio 2010, and being the conscientious TDD’er that I am, the first thing I did was set up xUnit.net and TestDriven.Net so that I could write my first, failing test. Instead of my expected test failure, I was greeted by this unfriendly error:
=== ERROR IN TEST RUNNER: xUnit.net 1.5 build 1479 ===
System.IO.FileLoadException: Could not load file or assembly 'file:///D:\Dev\DiceRoller\3rdParty\xUnit.net\xunit.runner.tdnet.dll' or one of its dependencies. Operation is not supported. (Exception from HRESULT: 0x80131515)
File name: 'file:///D:\Dev\DiceRoller\3rdParty\xUnit.net\xunit.runner.tdnet.dll' ---> 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.
I’m sure I could have fired up Google or poked around for a bit to solve this problem, but why bother when I have one of the xUnit creators right down the hall? Brad ran through the obligatory “you’re an idiot” checks (all of the files are there, the versions are right, etc.), and then showed me that I need to unblock the xunit.runner.tdnet.dll file, because it was copied from a network location:
After I clicked the Unblock button, I was able to run my test and I got the failure that I expected. I post this hoping it will help those less fortunate than me, who don’t have a xUnit creator close at hand. Happy TDD’ing!