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:

 

Unblock

 

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!

Comments

  • Anonymous
    August 06, 2010
    Just wanted to let you know this post was a big help!  I had the problem with NUnit after migrating some projects to VS 2010 and updating to the latest NUnit.  After stumbling around, found your post and was able to get it working again.  Thank you!

  • Anonymous
    October 21, 2010
    You are a proper Leg-End! Thaaanks.

  • Anonymous
    February 17, 2011
    I had this issue with a downloaded zipped Visual Studio project. After extracting the project and then opening it in Visual Studio, it gave the same error at compile time! Thanks to you I found out about the Unblock button (I unblocked the downloaded zip file and then everything works fine). A Big Thank you!!

  • Anonymous
    November 30, 2011
    Your post just helped me a lot! Thank you!

  • Anonymous
    December 05, 2011
    Helped me as well. Thanks so much. I had to close the solution and relaunch VS for it to work for me.

  • Anonymous
    January 22, 2013
    Thanks, this surely saved me a lot of time!

  • Anonymous
    June 07, 2014
    Actually had the same problem using MonoDevelop. Never would have found what to do if not for this!

  • Anonymous
    July 01, 2014
    Thanks a lot.. helped a lot, saved me loads of headache.

  • Anonymous
    August 01, 2014
    The whole day was lost until I found this topic. Thank you so much!  Microsoft writes misleading error messages. It's stupid to write "attempt was made to load an assembly from a network location” when obviously one runs a program from a local disk!  Why didn't they write something like: “attempt was made to load an assembly GOT from a network location. Try to unlock the assembly.”

  • Anonymous
    October 07, 2014
    Thanks a lot! This helped me so much, greatly appreciate this :)

  • Anonymous
    December 16, 2014
    Helped me out greatly, appreciate it!

  • Anonymous
    January 29, 2015
    At last, after searching for the answer for at least an hour, I found it here. The Holy Grail!

  • Anonymous
    February 24, 2015
    Thank you very much, really useful tip!!

  • Anonymous
    May 24, 2015
    Thank you for posting this. It's 2015 and this little tip is still helping people out when stumbling upon this cryptic error message :)

  • Anonymous
    June 24, 2015
    Awesome! Thanks very much for posting this! Lost a few hours troubleshooting until I decided to google this error message and discovered this post.

  • Anonymous
    August 04, 2015
    You literally saved my life today. I would've never thought to check if the .dll files were being blocked. It fixed my errors!