Metadata file ... could not be found error when building projects

Visual Studio-2008

Visual Studio-2008 Problem Overview


Every time I start Visual Studio 2008, the first time I try to run the project I get the error CS0006 The metadata file ... could not be found. If I do a rebuild of the complete solution it works.

Some information about the solution:

  • I'm building in debug mode and Visual Studio complains about not finding dll:s in the release folder.

  • The projects Visual Studio complains about are used by many other projects in the solution.

  • I have changed the default output path of all projects to a ......\build\debug\ProjectName and ......\build\release\ProjectName respectively. (Just to get all build files in one directory)

  • I have the same problem with a another solution.

  • The solution was created from scratch.

  • There are 9 projects in the solution. One WPF and 8 class libraries using dotnet 3.5.

Any ideas on what is causing this problem?

Visual Studio-2008 Solutions


Solution 1 - Visual Studio-2008

i had the similar issue where "metadata could not be found". on the solution property, make sure that the "build" check box is marked in Build/Configuration Manager for each project.

Solution 2 - Visual Studio-2008

This is usually caused by a project that is referenced in a different solution than the one that is throwing the error. If you clean the other solution, or branch the code, you will more than likely see this error. The solution is to scroll down your list of "metadata not found" errors, and look at the references to the projects. 9/10 times, you will see a broken reference to a project that is not in this solution. Add the projects to fix the reference errors, and rebuild. That should fix it.

(I just ran into this today, and have in the past, and this has ALWAYS worked)

Solution 3 - Visual Studio-2008

I had this issue, not sure if it will help but mine was caused by having two different versions of the same project referenced by two different solutions. When I built the solution with the reference to the correct project first the second solution would build fine, however, if I cleaned the first solution and tried to build the second solution it would fail with these dll reference error messages.

The solution for me was figuring out I had two projects with the same name which had been accidentally duplicated and removing the reference to the old incorrect project and adding a reference to the new one.

In any case it seems that these messages are a bit of a red herring, I would check your build output and find the first project that fails to build and very carefully check the references on that project.

Solution 4 - Visual Studio-2008

Another thing to verify is the path length... that causes also Metadata File not found and compilation errors... I just renamed my folders to shorter paths and voilá, classes that weren´t recognized and stayed black, turned blue just by renaming the folder.

Solution 5 - Visual Studio-2008

For me I had a project referenced in another project. It didn't show it was broken in the references list in the solution explorer window but I removed and readded it anyway. It builds just fine now!

Solution 6 - Visual Studio-2008

I went through all these steps in VS2012, but I kept running into this issue when building the solution as a whole (the individual projects built just fine with no errors).

I found that if you right-click on your Solution in the Solution Explorer and select "Build Order" you can see the order that VS is using to rebuild your solution. It's likely out of whack.

You can correct the build order by clicking on the Dependencies tab and selecting the projects that depends on other projects in the solution and checking the projects they depend on. Once you hit okay and do a rebuild of the solution, you should be good to go.

Solution 7 - Visual Studio-2008

The way I've got round this in the past in VS2005 as well as just now in VS2008 is to make sure all of the dependancies are correct and the references are pointing to the projects not the dlls. Then go through and manually build each project in dependancy order. Once the last one builds you can run a full solution build and its fine.

This answer is for future reference for others as I know the question is over 15 months old.

Cheers

Solution 8 - Visual Studio-2008

I have a couple of points I would like to make.

If you are relying on the solution file as your build file under MSBuild, ensure that you add projects to the solution file in the order in which you want them to build, i.e., based on the mutual dependency order of the projects. This becomes very important if you have projects in the solution that other projects depend upon, but the references have been added as "References" rather than as "Project References".

You should avoid that like the plague, but in case you do need to do that, then at least make sure the dependent projects appear earlier in the solution file.

You should bear in mind that the way Visual Studio generates build order is not exactly the same as the way MSBuild does it. This is because MSBuild primarily depends on the project file to tell it what the dependencies are, whereas Visual Studio can also save them in the soltuion file. Therefore, you can sometimes see situations where Visual Studio builds the solution perfectly, but MSBuild just can't do it.

I have had a couple of instances where I had to hand tweak the order in which the projects appear in the solution file as well as the order in which the projects were listed in the ProjectReferences element in a Web Site project in the solution file.

I hope the above information helps.

Solution 9 - Visual Studio-2008

If you use LinqtoSQL Data contexts, for instance, and the .designer.cs file is missing, you will get the Metadata file could not be found error.

Recreating the designer.cs file is easy.

Open up the dbml using xml view. Add a blank line, then remove it, then save. That should regenerate your designer.cs file.

Under some circumstances, if you have code inside your data context's code-behind, this work around will not work. In this case, take the code out of the code behind and put it in notepad or something. Do the trick of adding then removing a line from the DC and save. Now put the code back and save.

Solution 10 - Visual Studio-2008

I have a similar problem each time I update the project from SVN.
Another solution for ASP.NET:

  1. Close the IDE.
  2. Delete the files in C:\WINDOWS\microsoft.net\framework\v…\Temporary ASP.NET File\.

Solution 11 - Visual Studio-2008

I also experienced this error and the cause was that the Project is referencing to itself. I have no idea how it happened but I just removed the reference and voila

Solution 12 - Visual Studio-2008

In my case, I found out that one of my solution was referencing something that wasn't there on the computer (VBIDE). Once i removed the offending reference, the rest of the projects built correctly. Hope that helps someone.

And in another situation, I moved some code from one project to another, and that piece of code was referencing Json.net. I manually added a reference to Json.net but that made the problem come about it. I solved it by installing Json.net through NuGet and that made the problem go away. Hope that helps someone.

Solution 13 - Visual Studio-2008

First make sure that the "build" check box is marked in Build -> Configuration Manager for each project.

In case, if you already have all projects selected under Build -> Configuration Manager menu, and restarting VS trick doesn't work for you either than you have to find the reference of the file(s) (could be dll or cs) in your project and delete those references manually. Those file(s)/reference(s) should be displayed with yellow icon. The error definitely guides you which project of solution you should be looking into.

The reason of this error is because you have deleted file(s) manually in windows explorer and VS hasn't updated the reference and trying to locate the file which doesn't exist anymore!

Solution 14 - Visual Studio-2008

Same thing happened. I have several solutions referencing the same library projects (.net 3.5). I noticed when one was built in debug/normal config, and another using some other compiler directive (sqlite/local mode), this would happen. Simply get both projects building with the same directives and you should be fine.

Solution 15 - Visual Studio-2008

If you've add a new project to the solution, check that this is in the build list (see the Configuration Manager)

Solution 16 - Visual Studio-2008

I got stuck with the save issue when I wanted to include a dll file generated by Matlab. And I finally solved it by copy a .ctf file, which means certificate I suppose, and a .netmodule, which is needed for proper operation of the .dll, along with the .dll file. And that actually worked! So, my suggestion is to check if the .dll needs any other files to get along with.

Solution 17 - Visual Studio-2008

Windows 7 Ultimate 32 Visual Studio 2008 SQL Server v2005

I was receiving the same error. And I decided to remove and re-add the project references. I was unable to add them back because the Database reference in each of the referenced projects was blank.

Once I reset the database reference to the correct setting, I was able to build without further issue. Additionally, this was my first attempt to rebuild this project after having branched source code in VSS.

Good Luck

Solution 18 - Visual Studio-2008

I had this error it was caused by one of my project dependencies where the assembly name had been changed in the project, but the reference was not updated. So updating the reference or renaming the assembly back will fix it.

Solution 19 - Visual Studio-2008

EE

  • In My case the problem was in the project which has the Entity framework, open the diagram drag any table 2 cm :) and save, the VS will update all his links to the DB ...build this projects and build the solution, Buildssss.

Solution 20 - Visual Studio-2008

The only thing that fixed me (because I'm not running VS2010 on an administrator account) is to manually move the environment variable VS120COMNTOOLS from System Variables to User Variables.

Solution 21 - Visual Studio-2008

Deleting the entries of all source files which are no longer present in the source control and the file system from your .csproj file worked for me.


Detailed approach:

Well, my following 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.

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


Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionRobert HöglundView Question on Stackoverflow
Solution 1 - Visual Studio-2008Uprock7View Answer on Stackoverflow
Solution 2 - Visual Studio-2008Chris T.View Answer on Stackoverflow
Solution 3 - Visual Studio-2008Shaun DAmicoView Answer on Stackoverflow
Solution 4 - Visual Studio-2008Paul EhmigView Answer on Stackoverflow
Solution 5 - Visual Studio-2008Josh PView Answer on Stackoverflow
Solution 6 - Visual Studio-2008DanView Answer on Stackoverflow
Solution 7 - Visual Studio-2008WestDiscGolfView Answer on Stackoverflow
Solution 8 - Visual Studio-2008Umar Farooq KhawajaView Answer on Stackoverflow
Solution 9 - Visual Studio-2008lithium6941View Answer on Stackoverflow
Solution 10 - Visual Studio-2008maksim09View Answer on Stackoverflow
Solution 11 - Visual Studio-2008JessiePilorView Answer on Stackoverflow
Solution 12 - Visual Studio-2008Eddie EdwardsView Answer on Stackoverflow
Solution 13 - Visual Studio-2008Haseeb SdView Answer on Stackoverflow
Solution 14 - Visual Studio-2008RyanView Answer on Stackoverflow
Solution 15 - Visual Studio-2008Richard S.View Answer on Stackoverflow
Solution 16 - Visual Studio-2008Jingyu LeiView Answer on Stackoverflow
Solution 17 - Visual Studio-2008EJ RalstonView Answer on Stackoverflow
Solution 18 - Visual Studio-2008Darrell CummingView Answer on Stackoverflow
Solution 19 - Visual Studio-2008Bishoy HannaView Answer on Stackoverflow
Solution 20 - Visual Studio-2008RyanView Answer on Stackoverflow
Solution 21 - Visual Studio-2008VikramView Answer on Stackoverflow