Metadata file '.dll' could not be found

Viewed 1029825

I am working on a WPF, C# 3.0 project, and I get this error:

Error 1 Metadata file
'WORK=- \Tools\VersionManagementSystem\BusinessLogicLayer\bin\Debug
\BusinessLogicLayer.dll' could not be found C:\-=WORK=- \Tools
\VersionManagementSystem\VersionManagementSystem\CSC VersionManagementSystem

This is how I reference my usercontrols:

xmlns:vms="clr-namespace:VersionManagementSystem"
<vms:SignOffProjectListing Margin="5"/>

It happens after every failed build. The only way I can get the solution to compile is to comment out all my user controls and re-build the project, and then I uncomment the usercontrols and everything is fine.

I have checked build orders and dependencies configurations.

As you can see, it seems to have truncated the DLL file's absolute path... I have read that there is a bug with the length. Is this a possible problem?

It's very annoying and having to comment, build, and uncomment, the build is becoming extremely tiresome.

104 Answers

Visual Studio 2019 this worked for me:

  1. Close Visual Studio
  2. Delete the hidden .vs folder
  3. Reopen Visual Studio and rebuild the solution.

Most of the methods explained here did not solved the problem for me.

Finally, I fixed the problem by applying the following steps:

1. Close Visual Studio.

2. Delete all the contents in the bin folders of each project.

3. Open solution and rebuild.

I'd faced the same problem. In my case I'd referenced to a class library project with higher .Net version than my project and VS failed to build the project and raised the same error you posted.

I simply set .Net version of my class library project(the one that had broken the build) identical to the .Net version of referenced project and problem solved.

I had a class in 4.6.1 refering an interface that was in 4.6.2... upgrading the class to 462 fixed it.

In my case I had this error because, one of my project used a different .NET framework version from the others of the solution. I used the NuGet packages manager to install NLog, so, i think, it installed for the .Net version of this project.

I tried all solutions from this post, but none were working. I removed NLog, cleaned the solution and trid to compile: Same thing, CS006 error.

It was when I deleted all files in obj\Debug from this project that the solution compiled.

My issue came when i wrote c# 7 code but the project was using older version for .net framework

In VS 2019, under the project References check if there are any unresolved items by expanding Analyzers:

enter image description here

For me, there were two .dll files with wrong paths. Right click on each and select Remove:

enter image description here

Build the project, then build the solution. Done.

I had the same issue and another solution.

The issue: One solution, multiple Projects. The main application that uses some of the other results failed, saying:

CSC : error CS0006: Metadata file 'C:\Repos\TheApplication\TheApplicationCommon\bin\Debug\TheApplication.dll' could not be found

But actually this Project generated C:\Repos\TheApplication\TheApplicationCommon\bin\Debug\TheApplicationCommon.dll Another project that also uses the same dll compiled flawlessly.

Before I updated an internal NuGet-package that used PostSharp 3.x.x.x and now uses PostSharp 4.x.x.x. And my solution was to add this to my *.csproj file:

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="...">
  <Import Project="..." Condition="..." />
  <PropertyGroup>
    ...
    <AssemblyName>TheApplication</AssemblyName>
    ...
    <SkipPostSharp>True</SkipPostSharp> <!-- This line -->
  </PropertyGroup>
...

Another Solution->Clean, another Solution->Rebuild and it works locally and on the build server.

Hope it helps someone. The thread is old and quite long but this issue returns often and I didn't see this solution yet. Btw using Visual Studio 2017 (15.8.x).

In my case, I solved this problem after noticing that I had referenced a .Net Framework 4.7 project as a dependency on a .Net Framework 4.6.1 project. After migrating project 4.7 to 4.6.1 my application compiled normally

I have agree all aboves just a difference. In my case: I am using Visual Studio 2019. I closed VS-2019 and opened with VS-2017. and rebuild the project everything working great! For whom in my position date is: 4/19/2019

In my case, the parent folder of the solution had a %20 in the name. I renamed the parent folder by removing the %20 and the issue got fixed.

In Visual Studio 2019:

  • Close Visual Studio.
  • Delete the .vsccc file that lives in the same folder as your solution file.
  • Open the solution and rebuild.

I'd faced the same problem. First i cleared all nuget cache from tools>Nuget Package Manager>Package Manager settings then click "Clear All Nuget Cache(s)". After this opened Powershell and run "dotnet restore" then "dotnet build". In my case this solution fixed my errors.

Working with a Blazor WebAssembly ASP.NET Core hosted app, this problem arose when I deleted the WeatherForecast model and this caused a build error that wasn't visible as an error.

If this is the case for you, just remove the FetchData.razor file, and you'll be good to go!

I hit and solved this problem today on VS2022 in a solution with a Blazor project.

The underlying problem is that I had introduced a routine C# compilation error in C# code declared in a .razor file. VS2022 was dropping the display of the error from the Build Error List tab. I found the C# error by scanning the build output in the Output console log tab where my C# error was described as expected.

p.s. In case you are wondering, I had a Unit Test project referencing my Blazor web project. The project DLL reference from the Unit Test project to the Blazor app was complaining about the missing Blazor DLL.

For me the issue was that I had two Visual Studio windows opened, my project was running in debug in one window, and I tried to build it in another.

I had to stop debugging and then it let me build successfully.

I had the same issue in VS2019. Here is what you need to do:

  1. Push latest changes on some branch
  2. Delete the project
  3. Remove project from QuickStart - you can try to reference not existing project and it will ask you to remove
  4. Clone the project
  5. Run the project

I faced this problem. In my case I delete all bin and obj folders from all projects then this error will resolve for me. Try this for one more try to resolve the problem

I had an quite unusual case of this error, but maybe someone would benefit from it.

I had this error with missing .dll file of one of projects in solution (with target framework netstandard 2.0) I'm working on and at once error with reference (to Microsoft.Office.Interop.Word) this project uses.

This solution was cloned from git repository, and same solution compiled well for other people in my team.

I tried every propsed solution for issue - restarting VS, computer; cleaning project; checking and unchecking build checkboxes; checking if build order is proper etc.

I figured out that manifest of this project was not selected by default (dropdown of manifest in project properties was empty and disabled). Therefore I tried to add it, but nothing worked.

At last I started comparing this project .csproj file with one in other, older version of this project, which compiled without problem. After a bit of usless tries I figured out, that path to Microsoft.Office.Interop.Word is the same in both projects, even thought it was a relative path starting with lots of "go up" symbols ( ..\ ). And not working project was one level lower than other.

Adding one more "go up" symbol ( ..\ ) in reference path to Microsoft.Office.Interop.Word inside project .csproj file solved the issue.

I have no idea why this path was created that way and doesn't update in my case, while it work properly for others in my team.

This worked for me in VS2019 .Net Core, ASP.Net Core solution.

  1. Open a PowerShell console in the same location of the solution.
  2. Type dotnet restore to restore al packages and projects
  3. Type dotnet build. The solution will be built

Now it can be built also from Visual Studio IDE too. None of the other solution given worked for me

For me it was an unused import "using ApsNetCore" on a Controller. Removed it, clean, rebuild it and it worked.

in my case: go to add references. in reference manager window uncheck dll project for other projects. save it. again add reference dll project to other projects.

For me it is still a "feature" in the current version of VS2022.

  1. Building all ~80 projects of a solution
  2. Cancelling the build in the middle
  3. Unloading ~70 projects and doing a rebuild all

causes the error. Fix:

  1. Reload all projects
  2. Rebuild all up to the end
  3. then do the unload

and a rebuild all succeeds without that metadata error

Very strange! I tried all the previous answers and unfortunately nothing worked in my case.

I encountered two errors:

  1. Missing .dll file
  2. Method already defined at another place with the same parameters

I have cleared the second error first by removing the function which has been duplicated at another place.

My first error - that is .dll file missing has solved it on its own.

I want to say, if you have more than a single error along with the .dll missing file error, please try to solve the other errors first. Maybe the .dll error solves it on its own!

In my case, I had a bunch of other build errors as well (some simple type conversions) along with this one, I was scratching my head trying to solve this, and I wasn't focusing on the other errors.

What finally solved my problem was that I fixed all the other build error and then I build again and it build successfully.

So in case you have other build errors along with missing DLL file error, and nothing else is working for you then try to fix the other errors first and then build the solution again.

For me the problem was an error that didn't come up in the build output, namely I had two utility classes that were in different namespaces initially. I changed the namespace of the second one to match the first one's (without knowing there was another one utility class in the first one), and that's when this error started to come up.

I imagine the build output error surfaced, because the Logic Layer library DLL file could not be built, and the main application couldn't find it.

The solution was to change back the second utility class to a different namespace and that's when the real build errors started to pour in. After sorting them out the build went through just fine.

As an overview, if any of the previous solutions doesn't work for you, you might have suppressed errors in the code that Visual Studio is not showing, so try to retrack your coding steps and check for any irregularities.

PS: This was in Visual Studio 2015 Community Edition

The Visual Studio IDE doesn't do any building behind the scenes, the Msbuild application does. The VS IDE essentially just constructs the project file that is used by Msbuild and quite often it makes mistakes if you leave it up to the IDE to figure things out on it's own. If you are getting the Metadata file '.dll' could not be found error it is likely due to the fact that the correct/expected assemblies are not being found. So perhaps Visual Studio might be creating a project file for a 4.5 framework app, and expecting 4,5 assemblies, while you are referencing 4.0 assemblies. So look at your Visual Studio settings for incompatibilities or go into the project file yourself, and manually fix it by specifying the correct path <Reference Include="C:\\correct path to assembly\\yourAssembly.dll" />.

In my case inside my Web.config file changing this

<?xml version="1.0" encoding="utf-8"?>

to this

<?xml version="1.0"?>

fixed my problem

When I did a build, it would usually show errors like this in Visual Studio 2017:

Error   CS0006  Metadata file 'C:\src\ProjectDir\MyApp\bin\x64\Debug\Inspection.exe' could not be found MyApp   C:\src\ProjectDir\MyApp\CSC 1   Active

But sometimes an error like this would show for a couple seconds and then it would disappear and switch back to the above message:

Error   CS1503  Argument 1: cannot convert from 'MyApp.Model.Entities.Asset' to 'MyApp.Model.Model.Entities.Inspection' MyApp   C:\src\ProjectDir\MyApp\ViewModels\AssetDetailsViewModel.cs 1453    Active

So I spent time troubleshooting the first error but the real problem turned out to be due to the second error. First I had to delete all the /bin and /obj directories, then I also deleted the .suo files as indicated above. This allowed me to narrow down the problem to an interface issue.

In my interface I had this:

    Task<IList<Defect>> LoadDefects(Asset asset);

But in my actual implementation I had this code:

    public virtual async Task<IList<Defect>> LoadDefects(Inspection inspection)
    {
       var results ...
       // ....

        return results;
    }

The build completed successfully after I updated the interface to this:

    Task<IList<Defect>> LoadDefects(Inspection inspection);

So it seems like caching in VS caused it to keep showing the CS0006 error when the actual problem was the CS1503 error.

In my case it happened to me when I was referencing NuGet packages locally and moved their directory to somewhere else, I changed the path inside NuGet.Config but unfortunately I discovered that I should change the .csproject files manually to update the reference path, but the error message CS0006 was way far from describing this problem. Generally it also happens when there is a reference to DLL that couldn't be found, to be able to identify issue search your references in the project with the problem you will find some references with warning icon associated with them, try fixing those and it should work as expected.

A lot of these answers sound like trial and error. In my case though, it was simple: the referenced dll was not found in that particular location.

If you see the build errors, typically in this case, the build complains about many dlls. The key is to find the right dll that is missing. In my case, one of the projects in my solution had a direct dll reference instead of a project reference. So, I needed to build the project that outputs that dll before building the failing solution to make sure the failing solution finds the missing dll in that particular location.

Wow.. that was simple, but quite difficult to put it into words.

This issue can happen because you are using features that are not supported by the version of .net selected for the project.

In my case the reason was I used ?? operator to check for null and throw exception.

Strange enough that VS doesn't inform about the actual reason of the problem in the list of build errors.

But you can find this information in the Output logs of the build.

Deleting the bin/obj folders and then rebuilding the project worked for me.

In my case, what I believe happened was that I experienced a run time error the first time I built the project so my dll file was not not generated.

This happened when referencing a project from another. The project I was referencing was the one with the issue.

I got this issue after updating the dlls/nuget.

I could solve this manually by correcting the .csproj file. Mostly the version wasn't updated in the file. For example :

<Analyzer> Include="..\packages\Microsoft.CodeAnalysis.**VersionCheckAnalyzer.2.9.1**\analyzers\dotnet\Microsoft.CodeAnalysis.VersionCheckAnalyzer.dll"/>

<Analyzer> Include="..\packages\Microsoft.CodeAnalysis.**VersionCheckAnalyzer.2.9.7**\analyzers\dotnet\Microsoft.CodeAnalysis.VersionCheckAnalyzer.dll"/>

I had this error when tried to publish my project,

All answered above, not helped me...

I just change my deploy and the publish successed!

In my case it was that the dependor project (the project depending upon the one in the error message) was missing values in its "Assembly version" fields under the project's "Properties → Application → Assembly Information...". I just added in the same numbers which were there for "File version", clicked "OK" and the compiler errors disappeared!

Missing Assembly Version

It turns out that re-adding the AssemblyVersion then building the project again resulted in another error claiming that it was already present in the project. It was! Under the properties node of the project in Solution Explorer, there was a "SolutionVersionInfo.cs" file which also contained an AssemblyVersion attribute - deleting this file from the project resolved this error.

for me the problem occurred because I was in-lining variable.

so the following does successful build:

ReportCategory reportCategoryEnum;
Enum.TryParse(reportCategory, true, out reportCategoryEnum);

while when I modified my code as following, no errors were shown but build was failing

Enum.TryParse(reportCategory, true, out ReportCategory reportCategoryEnum);

In my case, I deleted the git folder and removed Git (Azure DevOps). This was the only method that I did that worked.

I tried clean, rebuild, reconfigure build, deleting bin and obj folders; nothing worked. When I removed solution of Git, voilá! It worked for me.

I don't understand, but this solved it for me.

I had a merge conflict in one .csproj file and ended up with two copies of one build target.

<Compile Include="SystemCodes\APSystemCodes.cs" />

After I eliminated the duplicate the build worked.

For me it was wrong folder name. If you close from source that replaces spaces with '%20', you will get such errors. Solution - just rename badly named folders.

Navigate to Solution's Folder Explorer and delete the unused project folder that was throwing error. In my case, after deleting the project, the folder was still present in the directory. After deleting the folder solution built successfully!

I got the same error using Visual Studio 2019. After a closer look on what was going on in the background i found out there were errors on appended class libraries which in turn were not compiling correctly and throughing at the same time the error "Meta data file not found". Corrected the errors, compiled it again and all worked.

In my case the answer was found on analysis of the output tab.

The framework version of the current project differs from remaining projects. Change of framework version to existing projects version will resolve this.

Nothing else here worked for me, but this did:

  1. Stash changes with Git
  2. Clean and build
  3. Apply stash
  4. Rebuild

Now, suddenly VS pointed me to an error that wasn't showing up before. Furthermore, there were several errors in that one file that intellisense was ignoring. I corrected those without the help of red underlines and then was able to successfully build.

I'm using VS 2019. Our group is supposed to upgrade from 2017 to 2019.

Actual solution

I tried to clone to a folder on my C: drive that was part of my roaming profile (so on the network). I created a local folder that was guaranteed to be untracked and cloned there instead. The issues went away.

Notes:

  • This could not have been a path-length issue because I also tried cloning it into a folder with a name longer than the original path, and it built fine.
  • This could not have been due to spaces in the file name because our solution folders have spaces in them.
  • This issue seems to only affect VS2019 and not VS2017. Though we have run into roaming profile issues before, it used to happen when we tried to sync with Git, not build.

Other things I tried/checked to no avail

  • Restart VS, logout, restart, etc.
  • Delete solution and re-clone from DevOps repo
  • No Build Errors in our code
  • Uncheck and re-check Build Configuration boxes
  • Build-order makes sense
  • All .NET Framework Targets the same. (In my case 4.6. Probably doesn't matter.)
  • DLLs actually exist in path
  • Reload project
  • Reinstall NuGet Packages
  • Re-add DLLs

Case Sensitive

In my case the error message was as follows

Severity Code Description Project File Line Suppression State Error The command ""C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.6.1 Tools\gacutil.exe" /i "C:\Users\cmaggiul\source\repos\consume-evalue-api\EValueApi\EValueApi\bin\debug\EValueApi.dll"" exited with code 3. EValueApi

I followed the path to the EValueApi.dll file and realized that the debug directory was capitalized in Windows. I changed the directory to be lower case ( to match the location being used by gacutil.exe and it resolved my issue.

In my case, I had a reference to another project which I deleted but I never used it in the code and therefore I didn't get any compilation errors.

Tip: Check if you have any references to other projects in your solution which do not exist.

I was facing the same issue with my project, I added console application in a solution but those other solution was not working and showing .dll not found, so I tried this method:

  1. Right click on the project which is having issue
  2. Click on Application tab, that is default
  3. Change output type Console Application to Class Library

I ran into this when doing a clean CLI rebuild of a MonoGame solution that had pure content projects.

The solution was to add a single dummy class file with an empty constructor to each of the content projects.

Related