Visual studio - getting error “Metadata file '

2020-01-29 03:51发布

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?

25条回答
对你真心纯属浪费
2楼-- · 2020-01-29 04:27

I had this problem for days! I tried all the stuff above, but the problem kept coming back. When this message is shown it can have the meaning of "one or more projects in your solution did not compile cleanly" thus the metadata for the file was never written. But in my case, I didn't see any of the other compiler errors!!! I kept working at trying to compile each solution manually, and only after getting VS2012 to actually reveal some compiler errors I hadn't seen previously, this problem vanished.

I fooled around with build orders, no build orders, referencing debug dlls (which were manually compiled)... NOTHING seemed to work, until I found these errors which did not show up when compiling the entire solution!!!!

Sometimes, it seems, when compiling, that the compiler will exist on some errors... I've seen this in the past where after fixing issues, subsequent compiles show NEW errors. I don't know why it happens and it's somewhat rare for me to have these issues. However, when you do have them like this, it's a real pain in trying to find out what's going on. Good Luck!

查看更多
别忘想泡老子
3楼-- · 2020-01-29 04:28

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

查看更多
劫难
4楼-- · 2020-01-29 04:29

I just ran into this issue and after an hour of screwing around realized I had added an aspx file to my product that had the same name as one of my Linq-To-Sql classes.
Class and Page where "Queue".
Changed the page to QueueMgr.aspx and everything built just fine.

查看更多
倾城 Initia
5楼-- · 2020-01-29 04:30

I had the same problem. In my case I had by mistake I had set all the projects apart from the project with the main method as console application.

To resolve I went to every project other than the one with main function and right click> properites > output type > class library

查看更多
放我归山
6楼-- · 2020-01-29 04:31

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.

查看更多
够拽才男人
7楼-- · 2020-01-29 04:32

it was happened to me because I've a strange clash in the namespaces: I had AssemblyA with namespace AssemblyA.ParentNamespace witch defines ClassA and in the same assembly another namespace with name AssemblyA.ParentNamespace.ChildNamespace witch defines a different ClassA (but with the same name)

I had then in AssemblyA.ParentNamespace IInterfaceB witch had a method that in the beginning returns IEnumerable and a ClassB witch implements IInterfaceB

I had later modified the method in ClassB to return IEnumerable but I've forgot to update the IInterfaceB definition, so the method there was still returning IEnumerable the fun fact was that the solution still complile if I did a rebuild all, but the tests witch refers AssemblyA didsn't work and returns the "Metadata file could not be found"error.

updating InterfaceB to correctly return IEnumerable as its implementor ClassB did solved the problem, unfortunately the error message was vague and also the fact that the compilation worked makes me suppose that maybe there is something to fix in the compiler

查看更多
登录 后发表回答