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

211.3k views Asked by At

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

47

There are 47 answers

0
bytecode77 On

In my case, I had some errors in my code. Visual Studio showed the error you had instead of the actual errors, like syntax errors or unknown class names. Try cleaning the solution and building project after project. This way you will discover the actual errors.

Again, this is just what cause the error for me.

0
user4603841 On

tldr: run dotnet clean && dotnet build from the command line resolves the issue. It appears to be a bug specific to Visual Studios. Running builds from Visual studios afterwards are successful.

** After having tried, cleaning, updating project debug and release configurations, etc. I realized the solution builds outside Visual Studios thereby implying it is a VS-specific bug. Subsequent builds in VS run successfully presumably because the missing DLLs are now present.

Why this happens to begin with is still a mystery.

0
Anthony Collins On

We recently ran into this issue after upgrading to Office 2010 from Office 2007 - we had to manually change references in our project to version 14 of the Office Interops we use in some projects.

Hope that helps - took us a few days to figure it out.

11
beauXjames On

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.
0
Julio Nobre On

Are you using a database code generation tool like SQLMETAL in your project?

If so, you may be facing a pluralized to unpluralized transition issue.

In my case, I have noted that some old pluralized (*) table names (upon which SQLMETAL adds, by default, an "s" letter at the end) table references to classes generated by SQLMETAL.

Since, I have recently disabled Pluralization of names, after regerating some database related classes, some of them lost their "s" prefix. Therefore, all references to affected table classes became invalid. For this reason, I have several compilation errors like the following:

'xxxx' does not contain a definition for 'TableNames' and no extension method 'TableNames' accepting a first argument of type 'yyyy' could be found (are you missing a using directive or an assembly reference?)

As you know, I takes only on error to prevent an assembly from compiling. And that is the missing assemply is linkable to dependent assemblies, causing the original "Metadata file 'XYZ' could not be found"

After fixing affected class tables references manually to their current names (unpluralized), I was finnaly able to get my project back to life!

(*) If option Visual Studio > Tools menu > Options > Database Tools > O/R Designer > Pluralization of names is enabled, some SQLMETALl code generator will add an "s" letter at the end of some generated table classes, although table has no "s" suffix on target database. For further information, please refer to http://msdn.microsoft.com/en-us/library/bb386987(v=vs.110).aspx

This post has lots of good advices. Just added one more.

0
Santoo On

same happened to me today as described by Vidar.

I have a Build error in a Helper Library (which is referenced by other projects) and instead of telling me that there's an error in Helper Library, the compiler comes up with list of MetaFile-not-found type errors. After correcting the Build error in Helper Library, the MetaFile errors gone.

Is there any setting in VS to improve this?

0
dynamiclynk On

I was having this issue when trying to add a project reference, and after a lot of searching and trying many of the things above, my build configuration and outputs were correct.

I finally just deleted the \bin and \obj folders from the source and referencing project.

Honestly I believe it was the obj folder not containing the correct metadata or corrupted metadata.

All is fixed now.

This was with Visual Studio 2015 - .NET 4.6 projects.

UPDATE:

The above worked on the first build, but on subsequent builds it failed, so I ended up recreating the solution file, and removing and reading the NuGet packages that were referenced incorrectly in my project files which pointed to the incorrect hint path.

That seemed to have fixed it thus far on subsequent builds.

A sample reference within a .csproj file

<ItemGroup>
    <Reference Include="Antlr3.Runtime, Version=3.5.0.2, Culture=neutral, PublicKeyToken=eb42632606e9261f, processorArchitecture=MSIL">
  <SpecificVersion>False</SpecificVersion>
  <HintPath>..\..\packages\Antlr.3.5.0.2\lib\Antlr3.Runtime.dll</HintPath>
    </Reference>
</ItemGroup>
0
Project Mayhem On

For me, I was using EntityFramework.6.2.0 Updated to EntityFramework.6.4.0 then problem is solved.

0
Lord of Scripts On

In my case it was caused by two things (VS.2012):

1) One of the projects was configured for AnyCPU instead of x86

2) A project that was referenced had somehow the "Build" checkbox unchecked.

Do check your Build | Configuration Manager to get an overview of what is being built and for which platform. Also make sure you check it for both Debug & Release as they may have different settings.

0
Aqil On

This issue has been resolved. I opened up the Package Manager Settings and clicked "Allow NuGet to download missing packages". The project now builds.

https://github.com/gitextensions/gitextensions/issues/1969

0
Mura On

I had the same issue, non of the provided answers fixed it before. Apparently this could be a problem with the .csproj file. For some reason the references to files that were not even made anywhere in my code were still "missing".

Open your .csproj file with a text editor and look for the files missing, delete, save and be happy.

0
Breeno On

Old question but I have encountered another variation of it. I had this issue when building a Xamarin iOS app, but the path in question looked more like

/.../MyApp/bin/Debug/netstandard2.0/ref/MyApp.dll.

Notice the /ref portion...

After some back and forth, it ended up being because the following line was present in the .csproj file for this project:

<ProduceReferenceAssembly>true</ProduceReferenceAssembly>

Not sure how/why that got added, or why the reference assembly is not produced, or even why the iOS project tries to use the reference assembly at all, but removing fixed the issue for me.

0
Bikey On

In my case, during a merge, it seems the solution file was missing some project references. Manually re-adding the project to the solution fixed it. You can also manually edit the solution file but you need to be careful and know what you are doing.

2
Vikram On

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.


0
mashta gidi On

I had the same problem. I noticed that my db context (EF4) that was located in the project dll wasn't recognize for some reason. I deleted it and created another one instead. and that solved it for me.

0
Hans Rudel On

I find that this usually occurs to me when i still have a method declaration in an interface, which a class implements, but that i had later removed and had forgotten to remove it from the interface as well. I usually just save the entire solution every 30mins n then just revert back to an earlier version if i cant find the error.

1
Vidar On

I had this problem and it was due to an invalid method in the offending library (dll) that did not return a value, e.g.

public bool DoSomething()
{
   //I never bothered putting code here....

}

When I commmented this out everything compiled :)

0
Juancentro On

It seems to happen when you checkout a solution with multiple projects that have references between them, and you haven't built it before. If you have references directly to the dlls, instead of referencing the project, you'll get this message. You should always use the Projects tab in the Add Reference dialog to add a reference to a project in the same solution. This way, VS can know the correct order in which to build the solution

0
Christophe Geers On

Had the same problem today.

My application, a Windows Forms applications, accidently had a reference to itself. Weird.

Once removed, the error went away.

The reference got added each time I dragged a user control, located in the Windows Forms project itself, to a form.

1
Ali Mahmoodi On

CHECK YOUR PROJECT PATH. It should have no irregular character like comma and space

for example this is incorrect path: d:\my applications\Project1

and this is true path d:\my_applications\Project1

The visual studio cannot build the project when there is a non alphabetic and numeric character in its path in disk and it show no message for this fault!

Also some installation tools have same problem when they start installation and can not be extracted.

0
Tarmo Elfving On

I had this problem and took long while to figure it out. Problem came up when I removed projects from solution and replaced those with nuget packages.

Solution seemed to be fine but the .csproj file still contained those projects multiple times as reference.

Seems that VS does not clean that file appropriately. It was still referencing the removed projects under the hood. When manually removed the references from csproj file all works again! wohoo

0
Guy On

Sometimes VS2010 switches my configuration from Any CPU to Mixed Platforms. When this happens I get this error message.

To resolve it I switch back to Any CPU:
1. Right click on the solution and select properties.
2. Click on Configuration Properties and then the Configuration Manager... button.
3. Under Active solution platform select Any CPU

2
dapim On

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.

0
juFo On

I had a similar problem. I removed classes and an interface and after this my builds started to fail.

  1. remove all builds so that no project builds (configuration manager)
  2. check the build order (take a screenshot and put it in Paint :D)
  3. enable one by one and do each time Clean & Rebuild and build.
  4. Now you know the project that failed. :-)

In my situation I had a Folder with one interface inside. e.g. FooSolution.StupidProject.Interfaces What happened is that I commented out the interface IUnicorns (FooSolution.StupidProject.Interfaces.IUnicorns), so that it would not be used anymore. No other project had IUnicorn in use anymore. Everything was fine.

However... some other projects were still having using statements to that folder:

using FooSolution.StupidProject.Interfaces

Solution:

  1. Instead of commenting the interface like,

    //public interface IUnicorn {

I commented also the namespace above the interface, like this:

// namespace FooSolution.StupidProject.Interfaces
//{
//   public interface IUnicorn {
  1. I searched my other projects and made sure there was no using anymore to that namespace!
  2. Clean and rebuild and a good coffee ;-)

Conclusion: check your usings in other projects.

1
jayasurya_j On

in my case i was working on a branch off master. so i checked out master branch, ran a build and then checked out my branch. It fixed the issue. If you already are on master, i suggest you check out previous commit and then build it.

0
Jim Jeffries On

For me this was caused by the Build target having been rewritten to not output the dll. Removing this to fall back on the default Build target fixed the issue.

0
Krishna On

In VS 2015, removing 'Analyzers' under 'References' solved the issue

0
AlexanderD On

Check wether the .vs folder in the project root is hidden or not. Mine wasn't (and it should) since I did a copy/paste from another pc. Deleting it solved the problem, Visual Studio 2015 just recreated it for me.

0
PineCone On

I had the same problem. Manually removing and adding the dlls did not help. ClassLibraries did not compile for all the projects and were missing in the ...\bin\Debug folder for the project [because I cleaned solution by mistake]. Since the class library did not compile that means there may be some errors somewhere in one of those sub projects.

Solution: Since my dlls were there for the ...\bin\Release folder, I tried to rebuild on Release mode and found an error on one line in one of the sub projects. Solving the error and rebuilding the solution got rid off the build error.

0
Carra On

I also had this problem today. Mine was caused by a cyclic dependency. Project A referenced Project B and vice versa.

0
Jen Grant On

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.

0
user1889439 On

This problem is due to pdb files or CodeContracts.

To resolve it:

  1. Clean your output folder and rebuild the solution.

  2. Re-Configure the CodeContracts or disable it for temporary build.

1
Shaun3180 On

I've also seen this error in solutions where I have multiple projects (usually netTiers projects where I've updated one or more of the sub-projects to target the 4.0 framework). It can be problematic to remove. Oftentimes it can be resolved, however, by first fixing all other errors in sub-projects (eg, any missing references), individually rebuilding those sub-projects, then removing/adding back any references to those sub-projects in Visual Studio. Personally, I've had little luck resolving this error by cleaning the solution alone.

0
Oscar Canek On

Most of the answares say that you need to remove the libraries of your solution, this is true but when you re-add the libraries the error will be shown again. You need to verify if all the libraries referenced have a compatible .net framework with the .net framework of your solution. Then fix all the errors in your code and rebuild the solution.

3
Adam Weitzman On

For me it's usually the target framework being off (4.5.2 instead of 4.6) If you fix the target framework of the project to match the target framework of the solution and build, a new .dll will be created.

1
Jamie On

I had the same problem myself.

Visual Studio 2013 only told me that it couldn't reference to it, and it couldn't find the metadata. When I opened my solution (which has multiple projects in it) it said that I was using projects lower than the framework version of one of my projects.

So I switched everything to version 4.5, and it worked again.

0
Eric Tilton On

I found out that the filepaths that were causing the issue were located in my csproj file within a bunch of <Analyzer> tags. It looked like this:

<ItemGroup>
    <Analyzer Include="..\..\path\path\path\bin\Microsoft.ReportViewer.Common.dll" />
    <Analyzer Include="..\..\..\..\path\path\path\bin\Microsoft.ReportViewer.Common.dll" />
</ItemGroup>

Deleting these resolved my issue.

0
BrainSlugs83 On

I ended up deleting my references (I had added them properly using the projects tab, and they used to build just fine), hand editing my .csproj files and removing bizarre entries that didn't belong -- and setting my outputs for debug and release, x86 and x64 and any cpu to all be "\bin" -- I built it once, then re-added the reference (again, using the projects tab), and everything started working again for me. Didn't have to restart Visual Studio at all.

0
User1551892 On

I had the same issue and the reason behind this issue is that the dll file of reference project is being used by some other process. In my case, I was debugging an application and application was attached with visual studio debugger. When I was re-building another application which is using same project, then I was getting this error. After de-attaching, I was able to build second application successfully.

0
Calin Vlasin On

For me was to remove/delete entire .vs folder(that is an invisible one) and then:

- Build
- Rebuild 

and done.

0
Hidden On

Re-open Visual Studio as Administrator.

0
Rob Koch On

The ~30th answer :-)

In VS2015:

  • Right-click on Solution
  • Select Project Build Order
  • Look at the list of projects in Project Build Order
  • Build each of your projects in that order
  • Inspect the Output

In my case, doing it step-by-step helped discovered what my problem is without all those errors thrown left and right.

If you had to know, I added Entity Framework (EF) 6.1.3 via NuGet when the project was set for .NET 4.5.2. I later downgraded the .NET Framework down to 4, and then the error was more obvious. Via NuGet, I uninstalled EF and re-added it.

0
Robert Harvey On

I seem to recall having a similar problem a few months ago. I solved it temporarily by copying the referenced DLL to the Release folder, thus satisfying Visual Studio's expectations. Later, I discovered the reference to the Release DLL in my actual code. You should try doing a search through the entire project for \release\project.dll.

Also, I have noticed that Visual Studio unit test projects sometimes put a "DeploymentItem" attribute on each of the test methods pointing to your target DLL, and if you switch between Debug and Release, Visual Studio can get confused if the DLL is no longer in the expected location. In my experience, these attributes can be safely deleted if you didn't put them there yourself as part of a "single deployment" scenario.

3
jasonh On

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.

3
OutOfMemory On

We have that problem quite often, but only with references to C++/CLI projects from C# projects. It's obviously a bug deep down in Visual Studio that Microsoft decided not to fix, because it's 'too complex' and they promised an overhaul of the C++ build system which is now targeted for Visual Studio 2010.

That was some time ago, and maybe the fix even went into Visual Studio 2008; I didn't follow up on it any more. However, our typical workaround was

  • Switch configuration
  • Restart Visual Studio
  • Build the solution
1
Totonga On

Did you check the Configuration manager settings? In the project settings dialog top right corner.

Sometimes it happens that between all the release entries a debug entry comes in. If so, the auto dependency created by the dependency graph of the solution gets all confused.

2
Darren Steinweg On

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.