62

I just added xUnit to our test project (for the Asserts, we're still using MSTest as the framework) and immediately the test runs refused to execute any of the tests. This is the error message:

Failed to queue test run '{ .... }' Test run deployment issue: The location of the file or directory '...xUnit.dll' is not trusted.

Jedidja
  • 16,610
  • 17
  • 73
  • 112
  • 2
    In VS2008 the built in test framework simply reports "Not Executed". What a lot of help that was! – Peter Morris Feb 09 '09 at 10:17
  • 7
    Jeez - whoever in MS decided that a location needed to be "trusted" just to run a fricken test needs shooting! – Calanus Mar 20 '09 at 13:03

10 Answers10

98

It took me a few tries to find the answer in Google, so I'm putting it here in case anyone else runs into the same problem. A detailed description can be found at this blog posting.

Basically, the fix invovles right-clicking on the dll file (xunit.dll for example) in Windows Explorer, going to Properties, and clicking "Unblock" at the bottom of the tab next to the 'Security' text. It seems that Vista / Windows 2008 will automatically mark assemblies that come from other machines or the internet as unsafe.

As a couple commenters have mentioned, you may also need to restart Visual Studio for this to take effect.

Jedidja
  • 16,610
  • 17
  • 73
  • 112
  • 1
    For some wierd reason I don't have the option to "UnBlock". There is no button. And I have the latest and greatest installed on my XP machine. – irperez May 27 '09 at 20:49
  • 7
    Thanks! After doing this, I had to restart Visual Studio to get the tests to run properly. – StriplingWarrior Mar 02 '10 at 22:21
  • 1
    Just to make it clear, you get to the 'Unblock' button by going to the dll's properties in Windows Explorer, NOT in Visual Studio. This confused me for a bit. – Rupert Bates Oct 05 '10 at 15:41
  • Great post - I had to Unblock Rhino.Mocks.dll after receiving some code via email. I did a VS Clean & Rebuild of the entire solution. After that my tests ran. – sheikhjabootie Nov 23 '10 at 23:00
  • Unblocking multiple DLL's in a folder: see http://www.paraesthesia.com/archive/2010/05/19/unblocking-multiple-files-at-once.aspx – Geert Jan 17 '11 at 12:35
  • First try did not succeed. Even restarting the PC. I had to delete my dll from the project and do the unblocking before adding it to the reference to make it work. – Arthis Feb 23 '11 at 15:10
  • Just want to add my bit of experience on the matter. If your DLL came from a zip file (that you downloaded for instance). Delete references to the DLL from the project. Unblock the zip file first, extract, then add the newly extracted DLL to the solution. – System Down Mar 07 '11 at 19:46
17

In my team we had the same problem.

Your solution didn't work, but this post by Charles Sterling did help.

We used the following line:

caspol -machine -addgroup 1 -url file://\\server/share/* FullTrust -name DevShare
Davy Landman
  • 15,109
  • 6
  • 49
  • 73
  • 1
    This is not needed any more after you install .Net 3.5 SP1, as this release changes the default trust level of network shares. Until you do install 3.5SP1 this is probably the best workaround. – Bert Huijben Apr 08 '09 at 22:55
  • 2
    @Bert Huijben, that's correct (http://stackoverflow.com/questions/148879/why-does-my-net-application-crash-when-run-from-a-network-drive/). But we kept having the problem even after 3.5SP1, but only when run via MSTest the error's would show up, just running the app, no problems. – Davy Landman Apr 09 '09 at 06:56
  • This one did not work for me originally on an XP box (see my alternate answer below) but it was the answer that did work when I moved to Win7/64. – Eric Mar 16 '10 at 21:25
10

After having this issue and burning hours trying to get "Unblock" to stick longer than a few minutes and/or figuring out caspol to no avail, I finally found a little tidbit via Google that the assemblies will be blocked again the next time you build or rebuild the project, since they're re-copied from their original source location. (I guess I never noticed that this happened before with references assemblies, but anyway...)

My fix for this was the following:

  1. Copy all the needed DLLs to another spot for safe-keeping

  2. Remove the references in Visual Studio

  3. Physically delete the DLLs in the bin folder

  4. Unblock the DLLs individually in the spot where they were copied off

  5. Add the references back in Visual Studio from the holding spot

Every subsequent build or rebuild worked fine afterward.

8

Running on an XP machine (even with .NET 3.5 SP1 installed) I was not able to get any of the other solutions listed here to work.

However working from the same post by Charles Sterling that Davy Landman references, I finally succeeded with this variation:

  1. Run the .NET 2.0 Configuration tool (Settings... Control Panel... Administrative Tools... .NET Framework 2.0 Configuration)
  2. Click down to "My Computer ... Runtime Security Policy ... Machine ... Code Groups ... All_Code"
  3. Create a new code group with membership condition of "Zone"="Local Intranet" and assign the permission set "FullTrust"
  4. Restart Visual Studio

After these steps I am able to run tests, including after restarts and rebuilds.

EDIT: as described in this answer, you may need to install the .NET SDK (which is different from the .NET framework) in order to have the .NET 2.0 Configuration tool on your system.

Community
  • 1
  • 1
Eric
  • 11,392
  • 13
  • 57
  • 100
  • When I later moved to a Win7/64 box, this approach did not work. However Davy Landman's 'caspol' solution above worked fine. – Eric Mar 16 '10 at 21:26
4

I had the same problem with moq. But would not 'unblock'. Every time I unblocked it, it was still blocked!?!?

I had to unblock the original zip file I downloaded. Then copy the DLL from the zip file again. It work after that.

Casey Burns
  • 1,223
  • 12
  • 15
3

It may seem really obvious now, but when I was clicking unblock the file was set as read-only.

Only after un-checking that attribute, applying, then selecting unblock did I actually get this working.

Give that a go.

:)

PS: I also deleted all the old dll's in my bin folder, just to make sure Visual Studio wasn't picking up the old one.

1

I had the same problem with downloaded DLLs blocked by Vista. You need Administrator rights to get the "Unblock" button on the file's Properties. I simply replaced the DLLs with the latest version from source control (TFS) where I had committed them before.

Simon Hohenadl
  • 502
  • 3
  • 8
1
  • Go to file
  • Right click and select Properties
  • On the first Register click on Allow
Marko
  • 20,385
  • 13
  • 48
  • 64
Yoel
  • 11
  • 1
0

I also tried opening the file in notepad++ and renaming it. Slightly different approach, but it worked for me. The local file system then think it comes from the same machine.

Deano
  • 2,805
  • 3
  • 29
  • 42
0

It's not just the moq.dll that needs to be unblocked. The latest zip file includes an moq.xml and moq.pdb file - referencing the dll copies these other two files to the bin folders as well. If all three have not been unblocked the tests won't run, I found.

haughtonomous
  • 4,602
  • 11
  • 34
  • 52