Error "Metadata file '...\Release\project.dll' could not be found in Visual Studio"

194,468

Solution 1

Everyone is correct...try everything...(in order of a little to a lot of time wasted)

  1. Do you have bad code? Fix that first.
  2. Clean Solution & Restart Visual Studio
  3. Remove / Add References
  4. Check your build order w/ larger projects and verify
  5. Manually rebuild sub-projects
  6. Manually copy dlls between projects into associated bin folders
  7. Go get some coffee, play some pinball and come back tomorrow...you may think of something else in the meanwhile.

Solution 2

I had the exact same problem. Big visual studio solution with 50+ projects.

All references were added as projects. Project build order was correct (right click on project and select build order).

However when building some of the higher level projects the "root" project they depended on were not built.

The problem was that these projects were not selected to build under the current configuration (don't know how this happened).

To check this select "Configuration Manager" (Build menu) e check if the problematic projects are set to build.

Solution 3

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):

  1. Restart VS and try building again.

  2. 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.

  3. 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.

  4. 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.

  5. 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.


Solution 4

When you say you deleted references to those projects and re-added them, how did you re-add them, exactly? Did you use the "Browse" tab in the "Add Reference" dialog in Visual Studio? Or, did you use the "Projects" tab (which lists neighboring projects in your solution)?

Edit: If you use the "Browse" tab, and manually add the reference to your .dll that is located in the /Release folder, then Visual Studio will always look for the .dll in that location, regardless of what mode you're currently in (Debug or Release).

If you removed the actual .dll file from the Release folder (either manually or by doing "Clean Solution"), then your reference will break because the .dll does not exist.

I'd suggest removing the reference to ProjectX.dll, and add it in again--but this time, use the "Projects" tab in the "Add Reference" dialog. When you add a reference this way, Visual Studio knows where to get the appropriate .dll. If you're in Debug mode, it will get it from the /Debug folder. If in Release mode, the /Release folder. Your build error should go away, and you also will no longer be (improperly) referencing a Release .dll while in Debug mode.

Solution 5

I've had this problem before and the only way I've found to solve it is to run Clean Solution and then restart Visual Studio.

Share:
194,468
nightcoder
Author by

nightcoder

Updated on December 16, 2020

Comments

  • nightcoder
    nightcoder over 3 years

    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 :(

  • nightcoder
    nightcoder almost 15 years
    I checked it. All projects have the same configuration.
  • nightcoder
    nightcoder almost 15 years
    I used "Browse" tab in the "Add Reference" dialog
  • nightcoder
    nightcoder almost 15 years
    After this problem disappears forever or just temporarily? And what do you mean by "switch configuration"? For example I always use Debug configuration. What should I do?
  • OutOfMemory
    OutOfMemory almost 15 years
    It disappears temporarily. Actually, it may not be a solution to you if you never switch configuration between debug and release. Or switching to release and then debug might fix it, who knows ;)
  • nightcoder
    nightcoder almost 15 years
    Well, a few days ago I switched to release, built the solution, and then switched back to Debug. After this the problem mutated :) : now I get only 1 such error instead of a few - it's like other projects have been "fixed" :)
  • nightcoder
    nightcoder almost 15 years
    It doesn't help in my situation, after short time the problem appears again.
  • Ken Pespisa
    Ken Pespisa almost 13 years
    Removing references from other projects (my UI and Test projects, for example), fixing the errors (in the Core project), building, and then re-adding those references did the trick for me.
  • splintor
    splintor over 11 years
    This is what fixed it for me.
  • Ravi Ram
    Ravi Ram over 11 years
    You need to clean up all ERRORS and get the solutions/project stable.
  • Wes Grant
    Wes Grant almost 11 years
    For me Visual Studio had created a projectname.v11 of type "Visual Studio Solution User Options". I deleted this file and restarted and everything was fine.
  • gonzobrains
    gonzobrains over 10 years
    I was going to write this same answer but noticed you already mentioned this issue. I had the same problem, where I did not return Boolean value and the error message for that problem got hidden amongst tons of other issues generated after the fact.
  • Robert Kaufmann
    Robert Kaufmann about 10 years
    Thank you! This worked out great for me when, for some reason, my release configuration did not build one of my projects.
  • Ricky
    Ricky almost 10 years
    This one just worked for me as well. Did multiple cleans and nothing worked. Once I did a clean and restarted, it started working again. How annoying.
  • jmbertucci
    jmbertucci almost 10 years
    Up voting this answer because we were running into this issue for a coworker. His system somehow lost most/all of his dependencies, so when building, it wouldn't build in the right order, cause the "metadata file for "whatever.dll" does not exist". We just walked through all his projects with another system to validate all the dependencies he needed for each project.
  • Vikram
    Vikram almost 10 years
    Good...I am glad that my answer was of some help to you.
  • Sooraj
    Sooraj over 9 years
    this happens because of the difference of names in the folder name and namespace name. If u create a namespace in a certain name , and later you rename it the namespace will have the old name itself. And the compilation will take the old path to find the .dll and .exe file . To avoid this open the .csproj file of each namespace with a text file , and find the old path in the file. remove this, clean and rebuild the solution. This worked for me. I spent an entire day working on this problem.
  • Chris Halcrow
    Chris Halcrow over 9 years
    If you don't have success and it's taking time, just go back to re-trying some of the basic things first. I started building sub-projects, still got errors, but then closed and re-opened VS, rebuilt the solution, all worked.
  • wingskush
    wingskush about 9 years
    Removing and add the reference again did the trick for me as well
  • NoLifeKing
    NoLifeKing over 8 years
    This was the same resolution I came to while having this problem. Some of the references used a Framework higher than my base application, when I changed the Framework in the base application to 4.5.2 (the same as the other references), the problem went away. Though, VS didn't say anything about different framework versions..
  • Roland
    Roland over 8 years
    The fun part was that Build All succeeded OK, but Publish Web App had the above error. I tried several of the described fixes, but eventually #2 worked for me. Good luck to all of you and Don't Give Up.
  • Dustin Oprea
    Dustin Oprea about 8 years
    Be aware of which .NET versions you're targeting. Make sure they're all compatible (or identical). Think of any projects you've added around the same time everything started having problems.
  • Jess
    Jess about 8 years
    I had mismatched namespace and project names in a home made referenced dll. Also, it was built with .NET 4.5.2 instead of 4.5. Man!
  • Tony S Yu
    Tony S Yu almost 8 years
    I had the same issue for a project that was created with an older version of Visual Studio. After updating VS, projects were created with a newer version of .NET and caused the DLL-not-found issue. (Go to properties pane for project to view/edit .NET version.) Thanks!
  • Rez.Net
    Rez.Net over 7 years
    I had the same issue, a referenced project had .Net 4.5.2 whereas the referencing one had .Net 4.5.
  • Nour Lababidi
    Nour Lababidi over 7 years
    Thank you million time (that is the number of other solutions I tried). This worked. For some reason the library I'm adding was targeting different .NET framework version than all the other projects
  • Chethan Shetty
    Chethan Shetty over 7 years
    You saved my life!
  • MerlinK
    MerlinK almost 7 years
    I commented the same thing on the top answer here: You should also check for files which aren't included in your solution or are included but not found. I had that problem when I was merging two branches and I think I accidentaly resolved the .csproj conflict with the wrong option. When I included all missing files and removed the non-existing ones from the solution (right-click on the file load/unload into project) the errors were gone.
  • Tim Sparkles
    Tim Sparkles over 5 years
    Try deleting the .suo file. It is relatively common for it to become corrupted.
  • EJoshuaS - Stand with Ukraine
    EJoshuaS - Stand with Ukraine over 4 years
    This answer is wrong. I have spaces in my path and it compiles just fine.
  • Tharindu
    Tharindu over 4 years
    Wow! I have tried so many options, nothing worked. But this fixed the issue! Thanks mate :)
  • derekbaker783
    derekbaker783 over 4 years
    Another potential cause of a similar error can be cloning a remote repo with URL-encoded spaces in the name such that the directory created by 'git clone' also contains those URL-encoded chars, while Visual Studio attempts to acquire metadata from the "clean" version of that directory/path structure (EX: 'my%20repo' versus 'my repo').
  • iCode
    iCode about 4 years
    I added a new Class Library project (dll) which was referenced in several other projects. The new dll was .NET Framework 4.8 while all other projects were 4.7.2. Changing the Target framework (in Project properties) to 4.7.2 fixed this for me. Thank you Adam!