Visual studio - getting error "Metadata file 'XYZ' could not be found" after edit continue

156,208

Solution 1

Eventually what solved the issue was:

  1. Clean every project individually (Right click> Clean).
  2. Rebuild every project individually (Right click> Rebuild).
  3. Rebuild the startup project.

I guess for some reason, just cleaning the solution had a different effect than specifically cleaning every project individually.

Edit:
As per @maplemale comment, It seems that sometimes removing and re-adding each reference is also required.

Update 2019:
This question got a lot of traffic in the past, but it seems that since VS 2017 was released, it got much less attention.
So another suggestion would be - Update to a newer version of VS (>= 2017) and among other new features this issue will also be solved

Solution 2

As far as I can tell, this happens when the project dependencies gets messed up for whatever reason (whilst all the inter-project references are still intact). For many cases, it is NOT a code issue. And for those who have more than a few projects, going through them one at a time is NOT acceptable.

It's easy to reset project dependencies -

  1. Select all projects and right click unload
  2. Select all projects and right click reload
  3. Rebuild solution

For those who have an issue in their code or some other issue that's causing this problem you'll obviously have to solve that issue first.

Solution 3

One possible reason could be you have upgraded the some of your projects (in the solution) to higher version e.g. from .NET 4.0 to 4.5 This happened in my case when I opened the solution in VS 2013 (originally created using VS 2010 and .NET 4.0). When I opened in VS 2013 my C++ project got updated to .NET 4.5 and I started to see the problem.

Solution 4

Generally this kind of error comes with human mistakes like if we change the namespace in some improper way, or changing folder names from explorer for current project etc, where compiler is unable to detect sometimes.

I came across the same error, to resolve which I tried few steps. Please follow all the steps :

  1. Clean whole Solution
  2. Right Click on every Project in your solution , Go to Properties and make your Default namespace as well as Default assembly name same as in your code (i.e namespace before class name)
  3. Check Folder names for each project by going through the explorer(Where your project solution is). If not matching with your project names, make it similar (Like step 2) to them.
  4. Remove all your references from each project relevant to another of same solution, and add it again.
  5. In Your Project Solution folder, you will find Visual c# Project file. Right click and open with Notepad. In your initial lines you would find for lines for every project like below:

Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "**Client**", "**Client** \ **Client**.csproj", "{4503E259-0E3B-414A-9074-F251684322A5}" EndProject

Check again Foldernames (I have highlighted in BOLD) and make it similar to what you did in step 2.

  1. Clean the whole solution again

  2. Build The Solution (If doesn't work try building individual after cleaning again)

Solution 5

Make sure all your dependent projects are using the same .Net Framework version. I had the same issue caused by a dependent project using 4.5.1, while all others were using 4.5. Changing the project from 4.5.1 to 4.5 and rebuilding my solution fixed this issue for me.

Share:
156,208

Related videos on Youtube

Avi Turner
Author by

Avi Turner

Updated on September 11, 2020

Comments

  • Avi Turner
    Avi Turner over 3 years

    I have stumbled into an issue that is really annoying.
    When I debug my software, everything runs OK, but if I hit a breakpoint and edit the code, when I try to continue running I get an error:
    Metadata file 'XYZ' could not be found

    After looking around for a while, I found some a similar issues, but they were all regarding a build failure, which is not my case (this happens only after edit-continue).

    What I have tried so far:

    • My code is compiling and running.
    • I cleaned the solution and restarted VS.
    • I made sure that the missing file's project is being build for the configuration I am running (in configuration manager).
    • I manually built the missing file's project.

    Some extra info:

    • It does not matter what I change, still get the same error (the change is not related to the missing file).
    • This happens also when I pause and continue (not only breakpoints)
    • I am running the project using a custom configuration (configuration manager...). When I run it using the default Debug configuration the error does not occur.

    Any ideas?

  • Avi Turner
    Avi Turner about 10 years
    Thanks for your comment, But I am not using any database code generation tools. And I did post what solved the issue. But who knows, Your answer might help the Googlers...
  • maplemale
    maplemale over 9 years
    I had to do this, but with an extra step. So, my startup project had references to other class library / dll projects in the solution. I had to clean each one individually and rebuild, but then also had to remove and re-add each reference. This seems to be a VS 2013 specific issue. I've never had to do anything like this in 2012 or 2010.
  • Michael
    Michael over 9 years
    Been having this problem in Visual Studio 2013 and Step 4 worked for me!
  • user1843640
    user1843640 over 9 years
    @Julio your answer helped me. I suffered from this in the past and forgot what the fix was. I came across your answer to this question and while not my exact situation it was enough to trigger my memory. I'm using Entity Framework db first with pluralization on and I run into this issue from time to time because one of my tables has a plural name while all the others are singular.
  • Avi Turner
    Avi Turner over 9 years
    That is not true. If it was, project would not compile and run, but the issues appeared in run time. In addition, as I have mentioned My code is compiling and running.
  • Muzammil Tamboli
    Muzammil Tamboli over 9 years
    I read comment 16 and followed it as I was struggling for sometime. Fortunately I realized one dll project called PDIAPI was failing due to wrong code and had to correct it. After its successful compilation I compiled referenced projects. It gave me success. I thought this could help others too.
  • Joezer
    Joezer over 9 years
    @Avi, tnx! I had to run the clean & rebuild thrice on all projects ... but eventually it worked.
  • adamdc78
    adamdc78 about 9 years
    I only ended up having to clean the project containing the file referenced by the error message on its own after a solution clean to resolve this issue.
  • Ben Wilde
    Ben Wilde over 8 years
    yeah... I have almost 70 projects - not doing this
  • user3752281
    user3752281 over 8 years
    @Ben, you can select them all, all the 70 projects, then exclude the ones than fail. Clean & build the selection and then Clen & Build the remaining projects.
  • Stoyan Berov
    Stoyan Berov over 8 years
    Same here, all but one projects were the same version!
  • Chris W
    Chris W about 8 years
    @BenWilde I have 124 projects, I won
  • mitaka
    mitaka about 8 years
    This usually happens when I have multiple instances of Visual Studio opened. Cleaning and Rebuilding projects help, but restarting the VS does the job most of the times for me.
  • Alvaro Pereira
    Alvaro Pereira about 8 years
    That's exactly what happened to me. the only difference is that I upgraded from .NET 4.5 to 4.6.1 in VS 2015
  • Tom Miller
    Tom Miller about 8 years
    Thanks for jogging the memory ;-) This is easy to overlook, sending one down a rabbit hole...
  • Carlos Toledo
    Carlos Toledo almost 8 years
    From there you can change the order of build for projects. Sometimes the dependencies are not sync.
  • dalcam
    dalcam almost 8 years
    Actually @Ben Wilde, im having to do this every time i get a branch in git. Did you find a permanent solution at all?
  • Mana
    Mana over 7 years
    thanks, this actually helped for med. Tried the first two solutions at top without luck.
  • Ben Wilde
    Ben Wilde over 7 years
    Sometimes upgrading visual studio keeps the problem from recurring.
  • Natalie Perret
    Natalie Perret over 7 years
    "What the craic?" I would have never ever expected such a trick to actually work... but it did! Sometimes I really don't get the black magic behind VS =/
  • MerlinK
    MerlinK almost 7 years
    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.
  • mattyb
    mattyb over 5 years
    I opened up the .csproj file and removed all usages / references to the missing metadata file and then re-installed it and it worked!
  • MarkD
    MarkD about 4 years
    Also happened to me - I changed the signature of a method in a class by adding a parameter, give it a default value but did not update the interface.