118

I know there is another question with exact the same problem, but I went trough all those answers, and none helped me. :( (This was the question.)

I just created a new ASP.NET MVC project and joined a few '.dll's in the solution. Now when I try to build the project I get the error message shown below on 3 of the 5 libraries.

Error   CS0006  Metadata file 'C:\Users\...\source\Database\bin\Debug\DataAccessLayer.dll' could not be found   Logic   C:\Users\...\source\Logic\CSC   1   Active

Error   CS0006  Metadata file 'C:\Users\...\source\Logic\bin\Debug\Logic.dll' could not be found    PTS2-MVC    C:\Users\...\source\PTS2-MVC\CSC    1   Active

Error   CS0006  Metadata file 'C:\Users\...\source\PTS2-MVC\bin\PTS2-MVC.dll' could not be found    PTS2-MVC.Tests  C:\Users\...\source\PTS2-MVC.Tests\CSC  1   Active

When I go to the bin\debug folder of that .dll, I see that it is empty, and the other .dll where I do not get an error message, is not empty. But I am clueless how to fix this or what I did to make this happen.

The most common answer is to go to the properties of the solution and go to configuration and uncheck -> apply -> check and apply again, but that didn't work

JYelton
  • 35,664
  • 27
  • 132
  • 191
Svenmarim
  • 3,633
  • 5
  • 24
  • 56
  • Just a guess, but it seems like VS cleaned those out. Im not sure what those dlls are or where they are from, but if you're the one that made them I'd make sure whatever solution they are in built them. If these folders are from what your current solution is building to then it wont find these once you clean your solution again. – TheNoob May 29 '17 at 23:15
  • Clean ^ rebuild || restart your visual , check again – Asif Raza May 30 '17 at 06:09
  • @AsifRaza I litterly did that already so many times, but thinking with me :) – Svenmarim May 30 '17 at 07:45
  • 1
    @TheNoob So you say i need to try and clean my solution and then build it? because i already tried that – Svenmarim May 30 '17 at 07:46
  • delete the all the from bin folder , then rebuild ^ check – Asif Raza May 30 '17 at 08:18
  • That issue mostly comes when you other build errors in any of the code files. Look at the output window for any errors not listed in the "Error List" window. This will give you a clue. – Shanmukhi Goli May 09 '18 at 09:58
  • The suggested fix of solution property pages->Configuration then uncheck 'Build' for all projects, Apply and then recheck and Apply again fixed the problem for me. I started receiving two extra errors which were the source of the problem but not previously showing. Once they were fixed everything compiled. – robs Aug 08 '18 at 06:12
  • 1
    This question Q& A thread lead to me solving my variation of the Metadata file problem. Unfortunately I will have to post my fix details in the much older alternative mentioned in the duplicate closure message above. – camelCase Apr 24 '22 at 14:41
  • rebuild the dll that points to that problem specifically. for me that was it. – Yulian Jul 05 '22 at 14:15

29 Answers29

158

The problem was that I had some other normal error messages in my project, and apparently after I fixed those and when I cleaned and built my project AGAIN, then all .dlls succeeded.

Make sure you don't have any other error messages in your project and if you do, fix those first!

Svenmarim
  • 3,633
  • 5
  • 24
  • 56
  • 7
    I actually had the same issue, but had no other Errors showing up, only the 1 error about the missing .dll. But then at some point (without me changing any code), suddenly a syntax error showed up that wasn't showing up before. Once I fixed that error, then like you said, I cleaned, rebuilt, and everything worked. – jbyrd Oct 27 '17 at 16:07
  • 29
    Same issue here. There seems to be a bug in the Error List window where errors don't show up sometimes (and other times errors which were fixed continue to show up, despite doing a clean/rebuild). The Output window is more reliable so check there when you run into this issue. – Santosh Feb 14 '18 at 12:55
  • 2
    I found that I had to enable warnings in my "error list" tab in visual studio. It was in the warnings that I saw that a referenced .dll could not be resolved. I had to remove the existing reference and add a new one in the correct directory. All is well now. – user1431072 Apr 11 '18 at 14:53
  • see my comment above, but basically same thing except some bug in VS was stopping the errors from showing until I unchecked/checked the Build options in the Solution property pages. – robs Aug 08 '18 at 06:15
  • Closing Visual Studio (20127), then deleting `.svn` folder from solution folder did the trick for me. – BlueStrat Aug 08 '18 at 22:37
  • This should not be the answer 'cuz it is the most obvious thing that could happen. For me the solution was a DLL path was hard coded and it was missing – canbax Oct 31 '18 at 06:07
  • @canbax, good for you that you found your own solution, but you can't say that this should not be an answer. Because apparently alot of people (including my self) forget this "obvious" answer. Alot of problems in SE are "obvious" problems, but it can still take hours before you finally figure out the issue. – Svenmarim Oct 31 '18 at 15:55
  • It was aspboilerplate architecure that I was working on and suddenly unexpected error happened and then started playing up that .dll was not found but it was the problem of other error as @Svenmarim mentioned in his answer. Thank you. – Ishwor Khanal Dec 22 '18 at 00:06
  • So, while it wasn't showing up as an error, there was a non-error blurb in the output window that keyed me in. I had references to a couple of .NET 4.6.1 assemblies, but my project was .NET 4.5. Make sure all your projects are at the correct .NET framework version. – Anthony Queen Feb 17 '20 at 20:06
  • This was absolutely the answer for me. Fix one "normal" error and all of those other dll errors went away. – TyngeOfTheGinge Mar 19 '20 at 23:45
  • My error was that I had an existing variable name as the name used inside a query :: `var wr = _repo.Query().Where(wr=> wr.Id == wrId).First();`. I fixed it by changing the inner variable to `WR` instead. For some reason this build error is only visible in the output window :/ – James L. May 04 '20 at 19:21
  • Same problem. The error didnt show in the error list, but after closing and reopenning VS, it showed the specific error. – Banana Cake Jun 30 '20 at 08:10
  • 2
    This is the only answer that really helped me. Superb! Thanks! – ɐsɹǝʌ ǝɔıʌ Aug 28 '20 at 12:36
  • This was the solution for me. The syntax errors appeared in the Error List panel once I manually started opening all the files one by one. – Lukas Feb 16 '23 at 21:46
54

Steps in Fixing this Error: MetaData File .dll could not be found.

  1. Clean All Projects.

  2. Unload All Projects.

  3. Reload All Projects.

  4. ReBuild Solution.

Then problem solved.

rjay dadula
  • 590
  • 4
  • 3
23

In my case, there was an error, but it was not properly parsed out by VS and shown in the "Error List" window. To find it, you much view the ol "Output" from build window and parse through the messages starting from top down and resolve the actual error. M$, please fix! This is a huge waste of time of the worlds collective developers.

ebol2000
  • 1,195
  • 11
  • 16
  • 3
    This resolved the issue for me. Tried all other solutions, but the output window pointed me to my project being built against netframework 4.7.2, which was higher than the targeted framework netframework 4.6. Just had to edit the .csjproj to point at 4.6. – Calum Mullen Feb 13 '20 at 09:38
17

Double check the name of your project folder. In my case my project folder was named with spaces in it. When I cloned the project from Team Foundation Server using git bash the spaces in the folder name were converted to: "%20". Changing those back to spaces fixed the problem for me.

roscoelee
  • 171
  • 1
  • 5
12

I had this issue with a solution containing multiple projects.

It came from duplicating a .csproj and adding the copy to the solution. A .csproj file contains a <ProjectGuid> element. I set the GUID of the copied project to a new one.

Update: Which GUID you use doesn't matter, it just needs to be different from the other project's GUID. You can create a new GUID from within Visual Studio: Tools -> Create GUID and copy the part between the curly brackets, i.e. {...}. Use that as the new value for the <ProjectGuid> element.

I also performed the following steps (not neccessarily neccessary, but they don't hurt):

  1. Close the solution
  2. Delete bin folder
  3. Delete all obj folders
  4. Open solution and build
j00hi
  • 5,420
  • 3
  • 45
  • 82
8

I fix this problem following this steps:

  1. Clean Solution
  2. Close Visual Studio
  3. Deleting /bin from the project directory
  4. Restart Visual Studio
  5. Rebuild Solution
Lucas Prestes
  • 362
  • 1
  • 4
  • 19
5

Another thing that you should check is the Target Framework of any referenced projects to make sure that the calling project is using the same or later version of the framework.

I had this issue, I tried all of the previously suggested answers and then on a hunch checked the frameworks. One of projects being referenced was targeting 4.6.1 when the calling project was only 4.5.2.

Rob
  • 51
  • 1
  • 3
4

For me cleaning and building didn't work. Unloading the project didn't work. Restarting Visual Studio or even the pc didn't work. This is what did work:

Go to each of the projects that are throwing the error, and in References, delete the reference to the problematic project and add it again. That solves the issue.

The problem seems to be related to moving a project around (Move it inside a folder for example), then a different project that references it, have its path wrong and can't find it.

David Perez
  • 478
  • 5
  • 17
  • I changed directories of my projects causing problem with dll's not building using rebuild all and this answer fixes my problem. – Alain Elemia Sep 19 '18 at 03:19
4

I had the same problem, even with no other errors showing on the "Error List" view after "Rebuild Solution". However, on the "Output" view, I saw the error that was behind the issue:

The primary reference "C:...\myproj.dll" could not be resolved because it was built against the ".NETFramework,Version=v4.6.1" framework. This is a higher version than the currently targeted framework ".NETFramework,Version=v4.5"

Once I corrected this, the issue was resolved.

Ian
  • 45
  • 5
3

I have the same problem, the problem was that solution path have spaces in the name and vs for some reason not resolve the package... download my repository again just renaming the solution with out spaces in the name.

e.g:

/Repo/Project Name/src

should be

/Repo/ProjectName/src
JonathanDavidArndt
  • 2,518
  • 13
  • 37
  • 49
D__
  • 141
  • 1
  • 5
3

What worked for me:

Package Manager Console (Visual Studio 2019 Comunity):

Install-Package NuGet.CommandLine
nuget locals all -clear

Rebuild solution.

s3c
  • 1,481
  • 19
  • 28
3

I have build 10 projects out of 25 projects in solution individually one by one based on dependencies. Then build the solution. It fixed for me

Siva Sankaran
  • 1,521
  • 4
  • 21
  • 40
2

Running this command in bash to delete all bins worked for me

$ find . -iname "bin" -o -iname "obj" | xargs rm -rf

Can't guarantee it'll work for anyone else though

Also be aware it'll delete all bin files -so you will have to rebuild all projects. Obviously best to cd into the relevant directory before using it.

Yair Halberstadt
  • 5,733
  • 28
  • 60
2

Cleaning my solution caused this problem with Visual Studio 2017. Unloading/reloading projects or more cleaning made no difference. Only thing that worked was closing and restarting Visual Studio.

John81
  • 3,726
  • 6
  • 38
  • 58
2

Check all the projects are loaded. In my case one of the project was unloaded and reloading the project clears the errors.

Maryam
  • 1,417
  • 4
  • 19
  • 33
2

In my case, I had to open the .csproj file and add the reference by hand, like this (Microsoft.Extensions.Identity.Stores.dll was missing):

<Reference Include="Microsoft.Extensions.Identity.Stores">
  <HintPath>..\..\..\..\Program Files\dotnet\sdk\NuGetFallbackFolder\microsoft.extensions.identity.stores\2.0.1\lib\netstandard2.0\Microsoft.Extensions.Identity.Stores.dll</HintPath>
</Reference>
2

Close Visual Studio, find the solution's .suo file, delete it, reopen Visual Studio.

Graham Laight
  • 4,700
  • 3
  • 29
  • 28
2

I had the same problem and i tried solutions from Metadata file '.dll' could not be found

but none of these worked.

So after trial and error i fixed it by unloading and reloading the project doing this reset the configuration file and fixed the issue.

Amad Malik
  • 21
  • 2
1

In my case I was facing same error. One of my project solution was referring an assembly from different NuGet location. I just changed it to correct location to solve this error and rebuild. and wow the project get build successfully and all other error gone away.

1

I had this same error. In my case I had built a library (call it commsLibrary) that referenced other libraries by including them as projects in my solution. Later, when I built a project and added my commsLibrary, whenever I would build I got the metadata file cannot be found error. So I added the libraries that my comms library referenced to the current project, then it was able to build.

Joseph Mawer
  • 288
  • 6
  • 16
1

After facing so many troubles, here is the solution that I found.

  1. open your project folder.
  2. find Your_Project_Name.csproj[Visual C# Project file (.csproj)]
  3. open that file in any text editor and find your missing file ItemGroup.

    <ItemGroup> <None Include="..." /> </ItemGroup>

  4. remove that ItemGroup and open once again your project and build

  5. If that reference is important for you then add once again.
rptwsthi
  • 10,094
  • 10
  • 68
  • 109
0

This issue happens when you renamed your solution and the .net framework cannot find the old solution.

To resolve this, you need to find and replace the old name of solution and all dependencies on it with the new name. If you need to browse the physical file through file explorer do so.

The files that are normally affected are AssemblyInfo.cs, .sln an Properties > Application > Assembly name and Default namespace. Make sure to update them with the new name.

Open the file explorer, if the folder with the old name still exists, you need to delete it. Then clean and build the solution until the error is gone. (If needed clean and build the project one by one especially the affected project.)

Matthew
  • 1,905
  • 3
  • 19
  • 26
0

I had the same issue. My problem was someone else on the team moved a class folder, and the project was looking for it.

For me, there were 44 errors; 43 ended in .dll (searching for a dependency) and the first one in the error list ended with .cs (searching for the actual class). I tried clean-build, and clean, unload, reload, build, but nothing working. I ended up locating the class in the project, and just deleted it, as it was showing up as unavailable anyways, followed by a clean-build.

That did the trick for me! Hope this helps.

Burke
  • 1
0

I had 2 files (and 2 classes) in the same project with the same name.

JohnB
  • 18,046
  • 16
  • 98
  • 110
0

In my case, I deleted one file directly from team explorer git menu which was causing this problem. When I checked solution explorer it was still showing the deleted file as unreferenced file. When I removed that file from solution explorer, I was able to build project successfully.

p4ulinux
  • 329
  • 5
  • 14
0

For me what worked was:

Uninstall and then reinstall the referenced Nuget package that has the error.

Andrew
  • 18,680
  • 13
  • 103
  • 118
0

In my case I run the tests and got error CS0006. It turned out that I run tests in Release mode. Switch to Debug mode fixed this error.

izimiky
  • 99
  • 1
  • 3
0

In my case the issue was, I was referencing a project where I commented out all the .cs files.

For example ProjectApp references ProjectUtility. In ProjectUtility I only had 1 .cs file. I wasn't using it anymore so I commented out the whole file. In ProjectApp I wasn't calling any of the code from ProjectUtility, but I had using ProjectUtility; in one of the ProjectApp .cs files. The only error I got from the compiler was the CS0006 error.

I uncommented the .cs file in ProjectUtility and the error went away. So I'm not sure if having no code in a project causes the compiler to create an invalid assembly or not generate the DLL at all. The fix for me was to just remove the reference to ProjectUtility rather than commenting all the code.

In case you were wondering why I commented all the code from the referenced project instead of removing the reference, I did it because I was testing something and didn't want to modify the ProjectApp.csproj file.

iheartcsharp
  • 1,279
  • 1
  • 14
  • 22
0

After working through a couple of issues in dependent projects, like the accepted answer says, I was still getting this error. I could see the file did indeed exist at the location it was looking in, but for some reason Visual Studio would not recognize it. Rebuilding the solution would clear all dependent projects and then would not rebuild them, but building individually would generate the .dll's. I used msbuild <project-name>.csproj in the developer PowerShell terminal in Visual Studio, meaning to get some more detailed debugging information--but it built for me instead! Try using msbuild against persistant build errors; you can use the --verbosity: option to get more output, as outlined in the docs.

NerdyGinger
  • 406
  • 7
  • 13