MSTest failed because source assembly is not trusted

I just added xUnit to our test project (for Asserts we still use MSTest as a framework), and immediately the test runs refuse to run any tests. This error message is:

Failed to start test run '{....}' Problem with deploying test run: file or directory location '... xUnit.dll' is not trusted.

+62
mstest
Oct 14 '08 at 14:15
source share
10 answers

It took me several attempts to find the answer on Google, so I put it here if someone else is facing the same problem. A detailed description can be found in this blog post .

Basically, the fix causes a right-click on the dll file (for example, xunit.dll) in Windows Explorer, go to "Properties" and click "Unlock" at the bottom of the tab next to the text "Security". Vista / Windows 2008 seems to automatically mark assemblies coming from other computers or the Internet as unsafe.

As a couple of commentators have already noted, you may also need to restart Visual Studio for this to take effect.

+98
Oct 14 '08 at 14:17
source share

We had the same problem on my team.

Your solution did not work, but this post by Charles Sterling helped.

We used the following line:

caspol -machine -addgroup 1 -url file://\\server/share/* FullTrust -name DevShare 
+17
Dec 04 '08 at
source share

After this problem and hours of work, trying to get "Unblock" to last longer than several minutes and / or find out caspol , to no avail, I finally found some tidbits through Google, the assemblies will be blocked again the next time you build or rebuild the project as they are re-copied from the original location of the source. (I think I never noticed that this happened before with assembly links, but anyway ...)

My fix for this was as follows:

  • Copy all necessary DLLs to other places for safe storage

  • Remove links in Visual Studio

  • Physically delete DLL in bin

  • Unlock DLL individually in the place where they were copied

  • Add links back to Visual Studio from while holding the spot

Each subsequent build or rebuild worked well after that.

+10
Feb 11 '09 at 20:59
source share

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

However, working from the same post of Charles Stirling that Davy Landman refers to, I finally succeeded in this option:

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

After these steps, I can run tests, including after a restart and recovery.

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 .NET 2.0 on your system.

+8
Dec 17 '09 at 21:06
source share

I had the same problem with moq. But do not "unlock". Every time I unlocked it, it blocked anyway!?!?

I had to unlock the source zip file that I downloaded. Then copy the DLL from the zip file again. He works after that.

+4
Jun 29 '10 at 3:48 on
source share

Now this may seem really obvious, but when I pressed unlock, the file was set as read-only.

Only after canceling this attribute, applying and then choosing unlock, did I really get this job.

Give it back.

:)

PS: I also deleted all the old dll in my bin folder to make sure that Visual Studio is not building the old one.

+3
Feb 20 '11 at 11:11
source share

I had the same problem with loadable dll files blocked by Vista. You need administrator rights to get the "Unblock" button in the "Properties" file. I simply replaced the DLLs with the latest version from the source control (TFS) where I used them before.

+1
Jul 30 '09 at 12:58
source share
  • Go to file
  • Right click and select Properties
  • In the first Register, click Allow
+1
Sep 19 '12 at 15:39
source share

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

0
Nov 12 2018-10-12
source share

It is not just a moq.dll file that needs to be unlocked. The last zip file contains the moq.xml and moq.pdb file - the link to the DLL copies these two other files to the bin folders. If all three have not been unlocked, the tests will not run, I found.

0
Aug 24 '11 at 10:52
source share



All Articles