Reputation: 13519
Recently I started to get this message randomly:
Metadata file '...\Release\project.dll' could not be found in Visual Studio
I have a solution with several projects in it. The current build mode is Debug and all projects' configurations are set to Debug. But when I try to run the main project - sometimes it gives me a few errors, all of which are "Metadata file '...\Release\projectX.dll' could not be found" - and, look, it says about RELEASE folder, though current mode is Debug. Why? I tried to search for reference to "Release\projectX.dll" inside all solution files, and I found one in ResolveAssemblyReference.cache file.
I made a good search over the Internet and found a few people with a similar problem, but there was no solution, or at least no working solution.
I tried to delete references to those projects and read them, but in some time I start getting these errors again.
It seems like a bug. Why does it search for referenced projects in Release folders when I always use Debug mode?
PS. For those who met this problem: I couldn't solve it in an easy way. It disappeared only after I reinstalled Windows :(
Upvotes: 142
Views: 220241
Reputation: 1425
tldr: run dotnet clean
&& dotnet build
from the command line resolves the issue. It appears to be a bug specific to Visual Studios. Running builds from Visual studios afterwards are successful.
** After having tried, cleaning, updating project debug and release configurations, etc. I realized the solution builds outside Visual Studios thereby implying it is a VS-specific bug. Subsequent builds in VS run successfully presumably because the missing DLLs are now present.
Why this happens to begin with is still a mystery.
Upvotes: 0
Reputation: 3166
Old question but I have encountered another variation of it. I had this issue when building a Xamarin iOS app, but the path in question looked more like
/.../MyApp/bin/Debug/netstandard2.0/ref/MyApp.dll
.
Notice the /ref
portion...
After some back and forth, it ended up being because the following line was present in the .csproj file for this project:
<ProduceReferenceAssembly>true</ProduceReferenceAssembly>
Not sure how/why that got added, or why the reference assembly is not produced, or even why the iOS project tries to use the reference assembly at all, but removing fixed the issue for me.
Upvotes: 0
Reputation: 56
I found out that the filepaths that were causing the issue were located in my csproj file within a bunch of <Analyzer>
tags. It looked like this:
<ItemGroup>
<Analyzer Include="..\..\path\path\path\bin\Microsoft.ReportViewer.Common.dll" />
<Analyzer Include="..\..\..\..\path\path\path\bin\Microsoft.ReportViewer.Common.dll" />
</ItemGroup>
Deleting these resolved my issue.
Upvotes: 0
Reputation: 579
For me, I was using EntityFramework.6.2.0 Updated to EntityFramework.6.4.0 then problem is solved.
Upvotes: 0
Reputation: 1
CHECK YOUR PROJECT PATH. It should have no irregular character like comma and space
for example this is incorrect path: d:\my applications\Project1
and this is true path d:\my_applications\Project1
The visual studio cannot build the project when there is a non alphabetic and numeric character in its path in disk and it show no message for this fault!
Also some installation tools have same problem when they start installation and can not be extracted.
Upvotes: 0
Reputation: 1617
in my case i was working on a branch off master. so i checked out master branch, ran a build and then checked out my branch. It fixed the issue. If you already are on master, i suggest you check out previous commit and then build it.
Upvotes: 1
Reputation: 71
I had the same issue, non of the provided answers fixed it before. Apparently this could be a problem with the .csproj file. For some reason the references to files that were not even made anywhere in my code were still "missing".
Open your .csproj file with a text editor and look for the files missing, delete, save and be happy.
Upvotes: 1
Reputation: 3071
I had the same problem myself.
Visual Studio 2013 only told me that it couldn't reference to it, and it couldn't find the metadata. When I opened my solution (which has multiple projects in it) it said that I was using projects lower than the framework version of one of my projects.
So I switched everything to version 4.5, and it worked again.
Upvotes: 2
Reputation: 2331
I was having this issue when trying to add a project reference, and after a lot of searching and trying many of the things above, my build configuration and outputs were correct.
I finally just deleted the \bin and \obj folders from the source and referencing project.
Honestly I believe it was the obj
folder not containing the correct metadata or corrupted metadata.
All is fixed now.
This was with Visual Studio 2015 - .NET 4.6 projects.
UPDATE:
The above worked on the first build, but on subsequent builds it failed, so I ended up recreating the solution file, and removing and reading the NuGet packages that were referenced incorrectly in my project files which pointed to the incorrect hint path.
That seemed to have fixed it thus far on subsequent builds.
<ItemGroup>
<Reference Include="Antlr3.Runtime, Version=3.5.0.2, Culture=neutral, PublicKeyToken=eb42632606e9261f, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\packages\Antlr.3.5.0.2\lib\Antlr3.Runtime.dll</HintPath>
</Reference>
</ItemGroup>
Upvotes: 0
Reputation: 4366
Did you check the Configuration manager settings? In the project settings dialog top right corner.
Sometimes it happens that between all the release entries a debug entry comes in. If so, the auto dependency created by the dependency graph of the solution gets all confused.
Upvotes: 3
Reputation: 199
We have that problem quite often, but only with references to C++/CLI projects from C# projects. It's obviously a bug deep down in Visual Studio that Microsoft decided not to fix, because it's 'too complex' and they promised an overhaul of the C++ build system which is now targeted for Visual Studio 2010.
That was some time ago, and maybe the fix even went into Visual Studio 2008; I didn't follow up on it any more. However, our typical workaround was
Upvotes: 2
Reputation: 1
This problem is due to pdb files or CodeContracts.
To resolve it:
Clean your output folder and rebuild the solution.
Re-Configure the CodeContracts or disable it for temporary build.
Upvotes: 2
Reputation: 1443
For me was to remove/delete entire .vs folder(that is an invisible one) and then:
- Build
- Rebuild
and done.
Upvotes: 1
Reputation: 626
Check wether the .vs folder in the project root is hidden or not. Mine wasn't (and it should) since I did a copy/paste from another pc. Deleting it solved the problem, Visual Studio 2015 just recreated it for me.
Upvotes: 0
Reputation: 73
Most of the answares say that you need to remove the libraries of your solution, this is true but when you re-add the libraries the error will be shown again. You need to verify if all the libraries referenced have a compatible .net framework with the .net framework of your solution. Then fix all the errors in your code and rebuild the solution.
Upvotes: 3
Reputation: 46
I had this problem and took long while to figure it out. Problem came up when I removed projects from solution and replaced those with nuget packages.
Solution seemed to be fine but the .csproj file still contained those projects multiple times as reference.
Seems that VS does not clean that file appropriately. It was still referencing the removed projects under the hood. When manually removed the references from csproj file all works again! wohoo
Upvotes: 2
Reputation: 1622
For me it's usually the target framework being off (4.5.2 instead of 4.6) If you fix the target framework of the project to match the target framework of the solution and build, a new .dll will be created.
Upvotes: 8
Reputation: 134
In VS 2015, removing 'Analyzers' under 'References' solved the issue
Upvotes: 0
Reputation: 1583
The ~30th answer :-)
In VS2015:
In my case, doing it step-by-step helped discovered what my problem is without all those errors thrown left and right.
If you had to know, I added Entity Framework (EF) 6.1.3 via NuGet when the project was set for .NET 4.5.2. I later downgraded the .NET Framework down to 4, and then the error was more obvious. Via NuGet, I uninstalled EF and re-added it.
Upvotes: 0
Reputation: 18587
I had a similar problem. I removed classes and an interface and after this my builds started to fail.
In my situation I had a Folder with one interface inside. e.g. FooSolution.StupidProject.Interfaces What happened is that I commented out the interface IUnicorns (FooSolution.StupidProject.Interfaces.IUnicorns), so that it would not be used anymore. No other project had IUnicorn in use anymore. Everything was fine.
However... some other projects were still having using statements to that folder:
using FooSolution.StupidProject.Interfaces
Solution:
Instead of commenting the interface like,
//public interface IUnicorn {
I commented also the namespace above the interface, like this:
// namespace FooSolution.StupidProject.Interfaces
//{
// public interface IUnicorn {
Conclusion: check your usings in other projects.
Upvotes: 0
Reputation: 4116
Well, my answer is not just the summary of all the solutions, but it offers more than that.
Section (1):
In general solutions:
I had 4 errors of this kind (‘metadata file could not be found’) along with 1 error saying 'Source File Could Not Be Opened (‘Unspecified error ‘)'.
I tried to get rid of ‘metadata file could not be found’ error. For that, I read many posts, blogs etc and found these solutions may be effective (summarizing them over here):
Restart VS and try building again.
Go to 'Solution Explorer'. Right click on Solution. Go to Properties. Go to 'Configuration Manager'. Check if the checkboxes under 'Build' are checked or not. If any or all of them are unchecked, then check them and try building again.
If the above solution(s) do not work, then follow sequence mentioned in step 2 above, and even if all the checkboxes are checked, uncheck them, check again and try to build again.
Build Order and Project Dependencies:
Go to 'Solution Explorer'. Right click on Solution. Go to 'Project Dependencies...'. You will see 2 tabs: 'Dependencies' and 'Build Order'. This build order is the one in which solution builds. Check the project dependencies and the build order to verify if some project (say 'project1') which is dependent on other (say 'project2') is trying to build before that one (project2). This might be the cause for the error.
Check the path of the missing .dll:
Check the path of the missing .dll. If the path contains space or any other invalid path character, remove it and try building again.
If this is the cause, then adjust the build order.
Section (2):
My particular case:
I tried all the steps above with various permutations and combinations with restarting VS few times. But, it did not help me.
So, I decided to get rid of other error I was coming across ('Source File Could Not Be Opened (‘Unspecified error ‘)').
I came across a blog: http://www.anujvarma.com/tfs-errorsource-file-could-not-be-opened-unspecified-error/#comment-1539
I tried the steps mentioned in that blog and I got rid of the error 'Source File Could Not Be Opened (‘Unspecified error ‘)' and surprisingly I got rid of other errors (‘metadata file could not be found’) as well.
Section (3):
Moral of the story:
Try all solutions as mentioned in section (1) above (and any other solutions) for getting rid of the error. If nothing works out, as per the blog mentioned in section (2) above, delete the entries of all source files which are no longer present in the source control and the file system from your .csproj file.
Upvotes: 17
Reputation: 945
In my case, during a merge, it seems the solution file was missing some project references. Manually re-adding the project to the solution fixed it. You can also manually edit the solution file but you need to be careful and know what you are doing.
Upvotes: 0
Reputation: 4405
Are you using a database code generation tool like SQLMETAL in your project?
If so, you may be facing a pluralized to unpluralized transition issue.
In my case, I have noted that some old pluralized (*) table names (upon which SQLMETAL adds, by default, an "s" letter at the end) table references to classes generated by SQLMETAL.
Since, I have recently disabled Pluralization of names, after regerating some database related classes, some of them lost their "s" prefix. Therefore, all references to affected table classes became invalid. For this reason, I have several compilation errors like the following:
'xxxx' does not contain a definition for 'TableNames' and no extension method 'TableNames' accepting a first argument of type 'yyyy' could be found (are you missing a using directive or an assembly reference?)
As you know, I takes only on error to prevent an assembly from compiling. And that is the missing assemply is linkable to dependent assemblies, causing the original "Metadata file 'XYZ' could not be found"
After fixing affected class tables references manually to their current names (unpluralized), I was finnaly able to get my project back to life!
(*) If option Visual Studio > Tools menu > Options > Database Tools > O/R Designer > Pluralization of names is enabled, some SQLMETALl code generator will add an "s" letter at the end of some generated table classes, although table has no "s" suffix on target database. For further information, please refer to http://msdn.microsoft.com/en-us/library/bb386987(v=vs.110).aspx
This post has lots of good advices. Just added one more.
Upvotes: 0
Reputation: 17964
I also had this problem today. Mine was caused by a cyclic dependency. Project A referenced Project B and vice versa.
Upvotes: 0
Reputation: 10081
For me this was caused by the Build target having been rewritten to not output the dll. Removing this to fall back on the default Build target fixed the issue.
Upvotes: 1
Reputation: 14860
In my case, I had some errors in my code. Visual Studio showed the error you had instead of the actual errors, like syntax errors or unknown class names. Try cleaning the solution and building project after project. This way you will discover the actual errors.
Again, this is just what cause the error for me.
Upvotes: 2
Reputation: 370
This issue has been resolved. I opened up the Package Manager Settings and clicked "Allow NuGet to download missing packages". The project now builds.
https://github.com/gitextensions/gitextensions/issues/1969
Upvotes: 0
Reputation: 3384
I had the same issue and the reason behind this issue is that the dll file of reference project is being used by some other process. In my case, I was debugging an application and application was attached with visual studio debugger. When I was re-building another application which is using same project, then I was getting this error. After de-attaching, I was able to build second application successfully.
Upvotes: 0
Reputation: 6411
I ended up deleting my references (I had added them properly using the projects tab, and they used to build just fine), hand editing my .csproj files and removing bizarre entries that didn't belong -- and setting my outputs for debug and release, x86 and x64 and any cpu to all be "\bin" -- I built it once, then re-added the reference (again, using the projects tab), and everything started working again for me. Didn't have to restart Visual Studio at all.
Upvotes: 1