When I try to run my Unit Test project, I get the following error:
Could not load file or assembly 'ASSEMBLY_NAME, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies.
The system cannot find the file specified.
The assembly under test is located in the same solution and every project target .NET 4.0 framework.
It worked for a while, but today I got this error again.
I can't figure out what is wrong, because the error message doesn't tell me enough. (like; WHICH file could not be found..)
I've tried to add a new Test project, but also that one worked for a while before it gave me this same error message.
Is there anybody who can point me in the right direction?
Edit: In the diagnostic build log, the following error appears:
C:\Program Files\MSBuild\Microsoft\VisualStudio\v10.0\TeamTest\
Microsoft.TeamTest.targets(14,5):
error : Could not load file or assembly 'ASSEMBLY_NAME, Version=1.0.0.0,
Culture=neutral, PublicKeyToken=null' or one of its dependencies.
The system cannot find the file specified.
Done executing task "BuildShadowTask" -- FAILED. (TaskId:671)
Done building target "ResolveTestReferences" in
project "ASSEMBLY_NAME.Tests.vbproj" -- FAILED.: (TargetId:985)
Check Build->Configuration Manager...
menu. All projects should have the same platform and column Build
checked.
Also you can take a look into output of the build (Output
window), it usually states more clearly which file could not be found.
After checking out some additional search results I came across this question here at SA Private Accessor for method is not found .
After I deleted the *.accessor file, my test project stopped complaining and compiled succesfully.
Everybody thanks for their help!
There is a common error about executing unit tests : the execution folder.
Are you sure your unit test is running in the correct folder ? Not in the famous obj folder ?
In the obj folder, only generated assemblies are copied, not dependencies -even copy local true-.
So if your test is launched from this folder, all the dependencies will missing.
I tried all above to no avail. Finally, in the csproj i changed
<Private>False</Private>
to
<Private>True</Private>
on the references and all tests passed.
Make sure Dependencies > Edit References > Project (you project) is selected and not .net Assembly of the project
Maybe enabling assembly loading logging can give you a hint about why your assembly cannot be loaded.
http://msdn.microsoft.com/en-us/library/e74a18c4.aspx
I had the same issue and found that copying the dll's to the GAC resolved the issue. Though I still don't understand why it doesn't use the referenced projects assemblies.
Another possible cause is if the assembly name of unit test project is using the same name as the assembly under test. (ie make sure your unit test assembly name is unique).
I had this error and I fixed it by UPDATING NUGET PACKAGES.
This worked because one of my projects in the solution was referencing a very old compiled version of another project that was contained in the same solution.
When I used "Run All" tests in Visual Studio, I suppose it copies over the "current" outputs of the projects, and then the nuget package dependency dlls afterwards, which overwrites the originals if they have the same name. (total guesswork there)
When I inspected the error message, I could see that my project was referencing "version 0.0.10" of a dependency, but my solution contained the project all the way up to "version 0.0.30", so massive difference.
References->Mark dlls->right click->properties->Copy Local set to true