Getting VB6 ADO application to work in Windows 7 - windows-7

I have inheritted several old VB6 applications that currently cannot be rewritten in .NET. These old applications all use ADO, and compile fine on my XP machine. Since switching to a Windows 7 machine, the applications compile fine, but when they are deployed (on XP machines), I get errors. This is a known issue that this Microsoft article discusses:
http://support.microsoft.com/kb/2517589
The article give a very detailed explanation of a workaround, which involved copying a ".TLB" file and registering it using "regtlibv12". When I attempt to register it, I get this error message:
RegisterTypeLib of C:\Program Files\Common Files\System\ado\msado60_Backcompat.tlb failed : 80029c4a
I have also tried registering this using the old "regtlib.exe" in the Windows folder, but got this error:
LoadTypeLib of C:\Program Files\Common Files\System\ado\msado60_Backcompat.tlb failed : 80029c4a
Because of this, I cannot continue with the work around. I would greatly appreciate any guidance anyone could give me on how to properly register this file.
Thank you in advance!

Put the .TLB file in an appropriate place like
C:\Program Files\Common Files\System\ado
Then open a new Project in the VB6 IDE (elevated, i.e. as admin). Choose Project|References... then click the Browse button. Navigate to the new .TLB file and open it. Check the box to select the item and close the References dialog.
It should be registered now.
If desperate, try VB Type Library Registration Utility.

You probably downloaded the file as C:\temp\Msado60_Backcompat_i386.tlb and didn't rename it. The example is for registering C:\temp\Msado60_Backcompat.tlb (note, no _i386).
Run the command with the correct filename.

Just to update this answer list based upon more recent information, Microsoft released KB 2640696 which addresses this issue in a more straightforward manner. This patch makes it much easier to deploy on your build machines and solves the downlevel OS issue as well.
A more complete picture of the patch can be found on the following blog post.

Related

not able to open VB project, getting error "C:\windows\system32\mscomctl.ocx" could not be loaded

I have a VB project was able to work without any issues, but now when i open the project i am getting the error with mscomctl.ocx.
I have re-registered the ocx but still am not able to load the project.
How can I fix this problem?
I was having this issue when I open the project on Windows 7 64-bit environment, it works correctly on win XP machine. I did a very simple change in project file earlier it says
Object={831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.1#0; MSCOMCTL.OCX
I changed 2.1 to 2.0 because I have seen it like that in many forums and it worked like charm.
The updated reference in VBP file is
Object={831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0; MSCOMCTL.OCX
it seems to me your project has lost its reference to the ocx (while it still tries to use some of the controls)
click on 'components' in the 'project' menu in the ide
in the list make sure 'microsoft windows common controls 6.0 (sp6)' is checked ... if it already is, try removing it, close (and save) the project, open the project, and turn it on again
I had the same problem. user1272267 answer worked (thanks), but it bothered me that I didn't understand why, I also wasn't sure if I would end up breaking the project for my colleagues who it worked fine for.
So I did a bit more digging and found that in the registry there was a key; reg hkcr\typelib{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}\2.0 (Note the 2.0)
I changed the 2.0 to 2.1 and hey presto, everything worked fine. I also checked the DLL and it turned out my copy was older than my colleagues copy. I think this may be because when I installed service pack 6 I kept some of the original files when asked since the replacement files were for American english and I had the UK version, but i'm not 100% certain of this
I had a similar problem when my Windows 7 32 bit laptop crashed and the company replaced it with a 64 bit machine... first I tried registering the .ocx using regsvr32 - on the 32 bit machine it would get unloaded from time to time... this did not work at all on the refurbished 64 bit machine...
I tried changing the .vbp file settings as noted in some of the earlier responses without success... I set the .vbp back to 2.0 and later on another issue I was searching the registry and decided to search for mscomctl.ocx and found 3 keys - 2.0, 2.1 and 2.2... since it wasn't working I decided to delete the 2.1 and 2.2 keys and voila! the controls loaded without a problem. Clearly the .vbp and registry have to match.
you can also open the project file (.vbp file) in notepad where you see something like the following :
Type=Exe
Form=frmComFX.frm
Reference=*\G{00020430-0000-0000-C000-000000000046}#2.0#0#C:\Windows\SysWOW64\stdole2.tlb#OLE Automation
Object={648A5603-2C6E-101B-82B6-000000000014}#1.1#0; MSCOMM32.OCX
Object={5E9E78A0-531B-11CF-91F6-C2863C385E30}#1.0#0; MSFLXGRD.OCX
Object={831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0; MSCOMCTL.OCX
Form=frmSetup.frm
Module=modFX; modFX.bas
IconForm="frmComFX"
Startup="frmComFX"
HelpFile=""
Title="ComFX"
Command32=""
Name="comFX"
the lines that start with 'object-' contain the registry key with which the ocx is registered ... you can now open regedit (start - execute - regedit) and search for this key .. be careful though what you do in regedit, you might screw up your visual basic installation or even your complete windows :)
of course you can also remove visual basic and reinstall it to get the registrations back
I had this same error. These 2 things worked for me:
Start Visual Studio 6 by right-click Run as Admin
or
Disable the UAC prompt.
hope it helps.
Try re-registering MSCOMCTL.OCX:
download the file: http://www.ocxdump.com/ocxfiles/M/MSCOMCTL.OCX
copy it in location c:\windows\system32\
open command prompt and run this:
cd c:\windows\system32
regsvr32 MSCOMCTL.OCX
Than try to run your application again.
Windows 7 64 bit; just installed VS6 and VS6 SP6 (with difficulty)but my project from Win XP gave the "MSCOMCTL.OCX could not be loaded" error.
I found Nathan Hadley's answer gave me the clue and allowed me to open the project....
My userinterface.vbp file for the project (copied from Win XP) had #2.2 next to the MSCOMCTL.OCX reference but my registry class id had only 2.1.
So I changed my userinterface.vbp entry to 2.1 and the project opened ok.
However the next day I ran the VB6 SP6 cumulative update VB60SP6-KB2708437-x86-ENU again (may have not installed properly the first time) and now I have version 2.2 in the registry.
So I changed my userInterface.vbp file back so the OCX reference has #2.2 once more and now the project still opens correctly and all runs ok.

Unable to Activate Windows Store App

I installed a retail version of Windows 8 Pro. I downloaded and installed Visual Studio Express 2012. I asked for and received a developers certificate. Then I tried to create a hello world app.
From there I get a "Unable to Activate Windows Store App" message box when I try to debug the app. Most commentary on the web says delete build directories. This didn't work for me
Does anyone have a solution for how to fix this and debug my app?
This happened to me once too, but the deleting build directories advice fixed it. Specifically, you just need to delete the bin\Debug and bld\Debug folders in your projects. Their contents will be regenerated by Visual Studio when you rebuild. I assume that this is only one project since it's a Hello World app; otherwise I would ask if you deleted build directories from all projects in your solution.
You can also try running "Clean Solution" from the BUILD menu in Visual Studio.
I'm sorry...it's horrible if this is happening on a clean install as you describe.
I ran into the same issue, and tried rebuilding, cleaning, deleting temp files, rebooting the computer, etc... and nothing helped.
Then finally I made a release build then went back to debug. And now it works.
I have no idea what happened, nor if that really helped, but it's worth a try.
For me a RESTART of pc solved this error message.
For me the problem was that I created the app on a TrueCrypt mounted virtual drive and when I moved the project files to a normal drive then everything worked just fine. Weird.
I was getting the exact same error. In my case the culprit was a NuGet package. It had added an app.config file to the project and it was confusing VS. I removed the app.config file and it solved my issue.
I got the solution at Iris Classon's site.
This can be solved by Uninstalling the app from the start screen then again building the app from Visual Studio.
I had a similar problem, and the cause was creating the project on a USB thumb drive. Creating a project on a normal hard drive volume works.
this can happen when the application signing key (.pfx file) is missing.
Try the following:
Open the Package.appxmanifest file in Visual Studio
Go to the register "Packaging"
Select [Choose Certificate…]
Select the test certificate using [Configure Certificate…] [From File…], or create a new one using [Configure Certificate…] [Test Certificate…]
When using a test certificate, ensure that it is in the .gitignore file. There should be an entry like !**\*_TemporaryKey.pfx to include the key in Git.
Note: The certificate for release build should only be available to the build server and not included in Git.
Rebuild the project
This has happened to me in the past and I have always found that deleting the build directories resolves it.
However this time this is not working for me.
I have tried
- Rebooting
- Deleting build directories
- Running Build | Clean Solution in VS
- Renewing Developer Account
The only thing that will work for me is changing my Package name under the Package.appxmanifest
However I am not overly happy with this as a solution. I will keep investigating.
The issue might be caused because NuGet will try to add an app.config with binding redirects to Windows Store apps if it thinks it is needed. However, Windows Store apps don’t need app.config, and will actually fail to start with a very confusing error message if it is present.
And the solution in this case would be to Remove the App.config
This error generally comes when you try to deploy in debug mode.
I would suggest, deploy the app first in release mode and then try in debug mode.
This worked for me.
Making a new certificate works for me. For this, go to Package.manifest->Packaging, and follow the Choose certificate.... Click on Configure certificate and select Create test certificate. Give it a name and press OK.
Increasing the revision number of the package worked for me
Tried so many of the above fixes. Nothing worked (deleting bin, obj dirs, editing the manifest, editing the registry, changing package name, etc, etc.) My Avast antivirus software was running and so I uninstalled it completely. That was it. App now runs fine.
This sort of problems are common with Windows 8 Visual Studio. Such errors encounters when your developer license of Visual Studio has expired so you may want to renew or get a new developer license here's how you get that. How to get a developer license in Windows 8
And similar problem may also encounter with E_Fail issues here's how to solve Unable to activate Windows Store app E_Fail Issue
For me, the fix was a combination of two of these answers -
Renew the developer license (How to get a developer license in Windows 8)
And deleting the build directories (though I deleted more then the screenshot depicted) Delete the Build directories
NuGet will try to add an app.config with binding redirects to Windows Store apps if it thinks it is needed. However, Windows Store apps don’t need app.config, and will actually fail to start with a very confusing error message if it is present.
Solution:
Remove the App.config
and build again
For those who get a similar error but who are searching for a solution while debugging an IOT background app on a local machine specifically - you can find it here.
Using the search term "unable to activate windows store app the activation request failed with error" brought me here.
Because of Two things i resolved this issue.
Basically, we just need to delete the bin\Debug and bld\Debug folders in our projects. Those contents will be regenerated by Visual Studio when you rebuild project.
Just Restart the Visual Studio. And Clean Build and Rebuild the solution and RUN it.
Hope this helps.,
Playing with this issue for 3 days, tried every suggestions, nothing works. Until now!!!
The solution was this for me:
renew developer licence
build and deploy solution in Release mode (after this step it still not worked, but VS installed some packages in rpi)
start VS remote debugger with default account (http://:8080/#Debug%20settings)
configure remote device with Universal authentication mode (VS2017 -> Project settings -> debug -> target device: remote machine, authentication mode: Universal (unencrypted protocol))
...and now I can sleep.
Hope it helps somebody.
This gift was courtesy of Microsoft's automatic updates for VS2015 which was one of the 2 culprits:
KB3022398
KB3165756
It also broke SourceTree and other apps that draw the GUI - making an outline of the app but not drawing the contents.
For me changing the Package Name in Package.appxmanifest fixed the problem
In my case, the C# UWP app had a native library which failed in the application startup code, and called exit(1). The symptoms were identical to those in the question, though. Visual Studio would throw a message:
Unable to activate Windows Store app '88888888-6666-5555-4444-111111111111_abcdefgh!App'. The Acme.exe process started, but the activation request failed with error 'Operation not supported. Unknown error: 0x80040905'.
In addition, there was a message in the UWP app Windows log under Microsoft\Windows\Apps\Microsoft-Windows-TWinUI/Operational: event ID 5961, message:
Activation for 88888888-6666-5555-4444-111111111111_abcdefgh!App failed. Error code: Unknown HResult Error code: 0x80040905. Activation phase: COM App activation
Internally, the C# part would try to construct a native class instance from the App constructor, the native class constructor would encounter an unrecoverable error and bail. From the UWP subsystem standpoint, and from the debugger standpoint, though, this looked as something distinct from the mere programmatic exit. I'll leave this answer here, 'cause I've spent some time chasing various UWP failure scenarios instead of running under a native debugger.
I've replaced the exit() call with throw ref new Exception(E_INVALIDARG). At least this way the error manifests in the managed debugger, and the message is descriptive.
I've been having this problem a lot with a UWP Windows 10 app on Visual Studio 2019...for me the reliable workaround is to bump the Build number in the Package.appxmanifest file (Packaging tab). It's a huge pain...really hope Microsoft will sort this out soon
Any existing error in the code can also cause this issue. Make sure your previous version of the code is working fine. Compare the difference and make sure all looks good.
I was getting this error and nothing else worked so I had to dissect my program. Turns out I referenced a StaticResource in my App.xaml that didn't exist.
Seems like a silly error but you'd also think Visual Studio would pick up on something like that and throw a different error so if nothing else works, double check your application resources.
As suggested by #Iman in a comment, in the UWP project settings, enable "Compile with .NET Native tool chain".
(After trying just about every answer in this question)

creating setup of a project in VB6.0

i have created a application in VB6.0 which is connected to MySQL through ODBC connection,there are two dsn which connects to application.Now i want to create a setup of the application that i can install on any computer.but how? I tried using Package and Development wizard in VB but it gives me error "access denied ieframe.dll" something like that while installing it AND also after using that wizard,now all my forms are corrupt.I craeted new and i don't want this to happen again.Help me!!
tired googling now!!!
I am not sure of the version of VB6 you are running, I do know that there was an InstallSheild Light version that shipped with Visual Studio 6 Professional. It was an optional install. If you have your original installation media try looking for it. There was also Visual Studio Installer 1.1 that used to be available from Microsoft. I found a link on Web.Archive.org that still works. I have used this to build msi files for VB6 in the past. You need to have Visual Interdev because it gets added as project type to it.
And since you mentioned that the Package and Deployment Wizard corrupted your project, you should make a backup of your data or use some type of source control. It will be a lot less painfull to recover when problems occur.
First of all, I take it that the two DSNs are not relevant to this problem?
I have never seen the error "access denied ieframe.dll", but I would guess that you are trying an installation via internet explorer. I would try creating a standard application installation.
I have to say that I am surprised to hear of "corruption" of your forms. Do you really mean your source code? Or this the forms in the executable. In any case, you really should be using some form of source control.
In any case, if you want a better answer, try giving a step by step run-throught of exactly what you are doing.
Regards,
Mark

VisualStudio2010 Debugging - The process cannot access the file ... because it is being used by another process

I'm unable to debug a WinForms C# application using the released version of Visual Studio 2010 Prof.
I get the following error message after the second debugging run.
Error 9 Unable to copy file "obj\x86\Debug\Arrowgrass Reports.exe" to "bin\Debug\Arrowgrass Reports.exe". The process cannot access the file 'bin\Debug\Arrowgrass Reports.exe' because it is being used by another process.
I've tried a pre-build script to attempt to delete this file, but it's locked by Visual Studio.
There are a few references to this on the net so it is a know problem. Does anyone have a hotfix or effective work-around?
I have found this issue very easy to reproduce, and the fix for me is a variation on Richard Fors' answer. If I have a UserControl open in the designer, run the debugger, and then edit the UserControl, the subsequent rebuild will fail. If I close the UserControl before running the debugger I never get this error, so I just make sure to close the designer window before hitting F5.
As of October 2012, I still have that issue so the VS 2010 SP1 didn't solve the problem. What I did, and worked consistently, was disabling the hosting process in the projects.
To disable the hosting process:
. Open a project in Visual Studio.
. On the Project menu, click Properties.
. Click the Debug tab.
. Clear the Enable the Visual Studio hosting process check box.
Source:
http://msdn.microsoft.com/en-us/library/ms185330(v=vs.100).aspx
You can try to kill the vshost.exe process:
taskkill /F /IM "Arrowgrass Reports.vshosts.exe"
You might also be lucky and simply be able to move the file in question. Moving the file can be done by adding the following lines of code to the pre-build event of your project:
if exist "$(TargetPath).locked" del "$(TargetPath).locked"
if exist "$(TargetPath)" if not exist "$(TargetPath).locked" move "$(TargetPath)" "$(TargetPath).locked"
Disabling windows search did not fix for me. However disabling Antivirus did (our Antivirus is Symantec Endpoint Protection 11)
As such, I was able to fix this for myself by changing the Debug settings in the project to point the working folder to a path on the C: drive, and then excepting that path from the antivirus auto-protect scan settings.
I hope this helps someone.
I posted this answer in a similar question but figured I'd also say it here:
Alright... this might sound pretty crazy.
I've had this problem in VS2010 for the last couple of years. The workaround mentioned here works for me, but a lot of times I forgot to close all my forms/usercontrols first.
I've discovered that merely going to view the open files via:
Computer Management (compmgmt.msc)->Shared Folders->Open Files
will "Free up" whichever file is being locked. Very strange, but it works for me!
In my case, I did Project Properties-->Security Tab-->Uncheck Click-Once security settings (If it is checked). It worked for me. In my project, it was showing this error for a C++ dll being used in my C# project.
The condition described can also be caused by the offending DLL or EXE referencing itself; in which case the Process Explorer test described previously never returns a match (e.g. it's not running). This unexpected situation seems to be caused during some sequence of operations in VS2010 (and likely all previous versions) which insidiously adds the reference behind the scenes. The specific cause of this hasn't been tracked down (or resolved that I know of). To check for, and resolve this error simply make sure the offending DLL or EXE is not listed as a reference to itself.
Got the error ("The process cannot access the file … because it is being used by another process") when I modified the (Visual Studio 2010 C# Express with SP1) solution from two large (10 source files, ~500 lines per file) projects with one referencing the other, to lots (6) of smaller projects with lots of projects referencing other projects.
The references were to the dll- and exe files (the Debug versions of them), NOT to the projects even though the projects were in the same solution.
I then learned that references should be to projects, not files, for F12 to work properly. So I modified the references. That made F12 work (jump to the source file instead of some auto-generated interface description), and at the same time the "cannot access file" error during build disappeared.
I only got the "cannot access file" error when doing Release builds. The references were to the Debug versions of exe/dll's. I suspect that this mixing is what triggers the bug in VS.
I encountered this issue when developing windows services. I found out that it happens when the service is running. Thus, you only need to stop the service (from the services.msc console) and you're good to go !
Hope this helps.
Tidjani.
Check Task Manager for the specified process and End the process explicitly. This solution worked for me.
I cant' write to a comment since not at 50 points but for me I excluded my project folder in ESET Enpoint Security ver 5. Seems like it blocked/hogged some files. My Error did not state which exe or file was in use so it took a long time to finally get to what JoeC said about Antivirus and tried it. Seems to be working now (Visual Studio 2010 SP1)
Closing recently changed User Controls solved the problem in my scenario. Hope this will help somebody out there.
Looks like this issue has (finally!) been fixed in the VS2010 SP1
http://www.microsoft.com/downloads/en/details.aspx?FamilyID=75568aa6-8107-475d-948a-ef22627e57a5&displaylang=en
Please try uninstalling Windows Live SYNC. Does it still happen?
I think I just found the culprit and the solution.
Go to services and stop & disable the "windows search" service.
That solved the problem for me now.
For me the solution was to change the startup project to a dll (problem only occurs in debug mode when having an application as the startup project). If your solution contains several projects (and it will, and it will contain a .dll, else you would not get the problem), switch to that .dll, no .vshost.exe, no problem.
Also, killing .vshost.exe did not work for me, since immediately after starting again, it had locked the .dll.
Also, make sure to have your references clean, especially in more complex projects, and also prefer project references to assembly references, and so on. I suppose bad references (circular and similar) are bound to cause problems, at least so I have read.
A short article by me on this problem (and my solution)
How to "clean up" your references in a solution
Adding the following to the Pre-build event of the shared dll worked for me:
if exist "$(TargetPath).locked*" del "$(TargetPath).locked*"
set exitprebuildfor$(ProjectName)=
for /l %%a in (1,1,10) do (
if defined exitprebuildfor$(ProjectName) goto :ok
if not exist "$(TargetPath).locked%%a" if exist "$(TargetPath)" move "$(TargetPath)" "$(TargetPath).locked%%a" & set exitprebuildfor$(ProjectName)=1)
:ok
set exitprebuildfor$(ProjectName)=
It's based on the solution given here but instead of just renaming the dll to .locked it keeps trying to rename it to .locked1, locked2. Using 10 I usually run into the problem once a day, but ant value can be used.
Simply make a copy of the whole project and run project from the new copy.... it will work fine.
But you will have to end process of the debug somehow in-order to delete the older project.
Stop IIS service and try building it again or if you can afford to restart your pc, give it a try. Worked for me both ways.
Cheers
My problem was that Outlook 2010 (outlook.exe) was using the same port as my ASP.NET MVC project with IIS express.
Solution: close outlook.exe, run your solution and open outlook again (so that it uses another port).
Hopefully this helps somebody, because I received the same error message as described in this topic.
Try deleting .exe file in debug or release folder (whatever you working on)
Windows will prompt that the process X has opened this and you can't delete it
after that go to task manager and in details tab end task X process
Delete obj file.And stop your service and Restart again.Then you may solve the problem
The best solution for me was to move my project files out of My Documents - which is on a server managed by the IT department - and locate them locally on my C drive. Also working: unchecking the "Enable the Visual Studio hosting process" checkbox, as stated by other people.
If you are working on a C# project which is using reference of C DLL, then you can eliminate the error by checking the Allow unsafe code check box. I know I have not used pointers in my C# project but I was using some bitwise operator in C#. May be these C-like features morphed it as 'Unsafe' code.
What worked for me was removing "read only" status on the bin folder. Once I did that, it has worked ever since.
I've had this error when the project is on a remote share (like, if your $env:homepath is helpfully redirected by your IT department to a network share). Make sure your project is resident on a local drive.
My problem started after creating a custom control and drag and drop it to the toolbox palette for use it in design forms. First appeared a warning saying that there was a redundance between the custom control source file (.cs) and the projects executable (.exe). On executing/debugging appeared the error: unable to access the (.exe) because it's being used (and it was true).
A literally removed the whole source code regarding the custom control and last problem never stopped, until I checked out the references and it was referencing itself in order to be "able to" get the former custom control. I removed the reference and done!!
So: just check the references and remove the self-reference to the project.
Delete your Bin folder and run the application.
This worked for me. :)
Simply turn off Visual Studio hosting in debug, run the project and again re on it and run project.
Open a project in Visual Studio.
. On the Project menu, click Properties.
. Click the Debug tab.
. Clear the Enable the Visual Studio hosting process check box
For Windows Project
The Visual Studio hosting process can hold the executable file pointer. To stop the host instance, open the Project properties and then go to Debug tab. Now uncheck the Enable the Visual Studio hosting Process option and then check the checkbox again to debug.
For web project
The IIS can hold the file pointer. Restarting the IIS can solve the issue.

MSTest run fails because source assembly is not trusted

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.
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.
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
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:
Copy all the needed DLLs to another
spot for safe-keeping
Remove the
references in Visual Studio
Physically delete the DLLs in the
bin folder
Unblock the DLLs
individually in the spot where they
were copied off
Add the references
back in Visual Studio from the
holding spot
Every subsequent build or rebuild worked fine afterward.
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:
Run the .NET 2.0 Configuration tool (Settings... Control Panel... Administrative Tools... .NET Framework 2.0 Configuration)
Click down to "My Computer ... Runtime Security Policy ... Machine ... Code Groups ... All_Code"
Create a new code group with membership condition of "Zone"="Local Intranet" and assign the permission set "FullTrust"
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.
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.
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.
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.
Go to file
Right click and select Properties
On the first Register click on Allow
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.
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.

Resources