Oliver
Oliver

Reputation: 36443

Metadata file '.dll' could not be found

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. Then I uncomment the usercontrols and everything is fine.

I have checked build orders and dependency 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.

Upvotes: 1000

Views: 1275345

Answers (30)

Super Jade
Super Jade

Reputation: 6374

I was building a solution that contained several projects targeting different .NET versions, including 4.6.1. My errors looked something like this:

Metadata file '...Project1.dll' could not be found
Unable to find package ...Runtime.. Project1
Unable to find package ...Runtime.. Project2

Solution

  1. See Visual Studio's Solution Explorer for any unloaded projects. Reload them. If Solution Explorer says you're missing components, install them.
  2. Exit Visual Studio.
  3. Go to File Explorer > %AppData% and delete NuGet.Cofing.
  4. Clean your repo of build objects by running this PowerShell command from the root of the repo. The command targets the src folder, which also must be in the root of your repo.
Get-ChildItem -Path "src" -Recurse -Include @("bin", "obj") | Foreach-object {Remove-item -Recurse -path $_.FullName }
  1. Uninstall .NET SDK 4.6.1 (or other suspected .NET SDK) using an offline installer downloaded from Microsoft.
  2. Reinstall the .NET SDK.
  3. Re-open the solution in VS and build.
  4. Watch your build succeed!

Upvotes: 0

vilem cech
vilem cech

Reputation: 185

Im running npm build of one project before the main build. When the npm build fails the main build doesnt build its references and then complains about missing .dll files and missing nuGet packages.

Upvotes: 0

Cata Hotea
Cata Hotea

Reputation: 1933

For me I checked the warnings not errors and noticed something wrong with one .dll in a bin folder.

I deleted that bin folder, Clean solution, Rebuild, all works now.

Upvotes: 0

alfi
alfi

Reputation: 401

In my case, it was an issue with my directory names.

If your solution path is something like My Project%2c Very Popular%2c Unit Testing%2c Software and Hardware.zip, it cannot resolve the metadata file, perhaps we should prevent some invalid words like %2c.

When a repository is cloned from certain sites, the directory name is URL encoded. Which would convert space characters in directory names to %20, forward slashes to %2f, underscores to %5f, etc. Although, I'm not sure why the % symbol is breaking things.

Renaming the path into one with valid characters resolved my issue. This can be done manually in the File Explorer. In my case, I just removed the %2cs.

Upvotes: 30

Garry Lodge
Garry Lodge

Reputation: 33

The issue for me was that someone had copied the source project into the project, added a project reference to debug an issue and then re-added the NuGet package without removing the project reference!

This actuall built on some dev machines and failed on others, depending on if it tried to use the NuGet package or the project.

Manually editing the project files to delete the project references resolved the issue.

Upvotes: 0

Joe Francis
Joe Francis

Reputation: 169

This might also be caused by the fact that you have multiple projects in your solution but different projects target different versions of .net framework.

Upvotes: 0

Dominik Teroerde
Dominik Teroerde

Reputation: 284

Sometimes a local project is automatically referenced twice. Check your .csproj file for something like this and remove one line:

  <ItemGroup>
    <ProjectReference Include="..\ReferenceProject\ReferenceProject.csproj" />
    <ProjectReference Include="..\ReferenceProject\ReferenceProject.csproj" />
  </ItemGroup>

Upvotes: 1

erenozten
erenozten

Reputation: 306

In my case, I mistakenly wrote #endregion twice. The problem was solved when I deleted one.

Upvotes: -1

Check that the project does not contain errors, otherwise the DLL cannot be generated

In my case, I had syntactic errors that were not visible from the Error List, when I checked the Output tab line by line I found some errors in the cshtml classes

Upvotes: 2

Art Hansen
Art Hansen

Reputation: 129

VS2022: Cause not found in the extensive listing already here.

Had a static class comprised entirely of static methods. Removing static from the class declaration didn't raise either a compile error or warning but did cause the OP build error.

Reverted the class declaration back to static and fixed the problem.

Upvotes: 1

Martin Seck
Martin Seck

Reputation: 519

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

Upvotes: 4

camelCase
camelCase

Reputation: 1790

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.

Upvotes: 6

Peter Lamberg
Peter Lamberg

Reputation: 8651

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.

Upvotes: 0

albinioni
albinioni

Reputation: 115

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!

Upvotes: 2

Reza Karimnia
Reza Karimnia

Reputation: 57

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.

Upvotes: 1

Ali Alizade
Ali Alizade

Reputation: 113

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.

Upvotes: 2

saggy
saggy

Reputation: 47

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

Upvotes: 0

Murat Yıldız
Murat Yıldız

Reputation: 12050

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.

Upvotes: 9

syned
syned

Reputation: 2321

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.

Upvotes: 0

Nicolette Anderson
Nicolette Anderson

Reputation: 59

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.

Upvotes: 2

Chris Maggiulli
Chris Maggiulli

Reputation: 3824

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.

Upvotes: 0

General Grievance
General Grievance

Reputation: 5023

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

Upvotes: 0

amr ras
amr ras

Reputation: 302

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.

Upvotes: 0

Hari
Hari

Reputation: 137

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

Upvotes: 0

Miguel Tom&#225;s
Miguel Tom&#225;s

Reputation: 1911

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.

Upvotes: 0

ragmn
ragmn

Reputation: 505

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!

Upvotes: 0

Cute pumpkin
Cute pumpkin

Reputation: 363

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.

Upvotes: 0

Jo&#227;o Neto
Jo&#227;o Neto

Reputation: 79

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

Upvotes: 1

Ilkin Sam Elimov
Ilkin Sam Elimov

Reputation: 698

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.

Upvotes: 3

rjacobsen0
rjacobsen0

Reputation: 1455

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.

Upvotes: 0

Related Questions