Error CS0006 Metadata file .dll could not be found (Solved)

I faced this error and it’s quite complicate to solve so I’m writing a post just to keep note and hopefully to provide some support to some other developers.
I spent a lot of time around this error and there are many reasons, ways and different scenarios because this error.
I had a look in internet and I tried any explicable and inexplicable workaround I found in Stackoverflow.

In my opinion is a common cause created by different things which are;

  • different .net version used by some of the libraries, sometime we inadvertently change that.
  • dependency breakdown in Visual studio, in that case we are able to build using MSBUILD but we can’t build using Visual Studio UI.
  • Nuget package not updated in one of the referenced libraries.
  • Project file with different configuration.

Quickest way to fix this issue is following some main steps:

  1. Fix the target framework, if you have few projects then is fine but if you have 70 projects or more then could be a problem so,
    download the Target Framework Migrator and in one click align all the target framework in all project, this is a great tool to do that.
  2. Fix nugget, enter in the nugget console

and execute Nuget restore SolutionName.sln

  1. Align and check the build configuration, right click on the solution and select properties.
    Select configuration properties and check that all the projects are using the same configuration.
    Check that all proper projects have the build checkbox selected.
    Some external project like WIX or SQL or others could have the build checkbox selected, if this is the case then check that the specific project builds correctly or uncheck the box and apply.
  2. Unload all the project from the solution and start loading each project starting from the base library.
    Every time you reload one then rebuild the solution.

At the end of this procedure the problem should be definitely solved.    

Related

Why X3M.AI Exists: Rethinking GRC and Security Execution

There’s a growing disconnect between compliance, risk, and the...

The Importance of Native Security Technologies in a Cloud Security Strategy

It's essential to embrace native security technologies in a...

Enhancing Security Operations with Microsoft’s AI-Powered Security Copilot

Microsoft’s latest innovation, the Security Copilot, is set to...

Do you want to optimize your Log Storage and Costs in Microsoft Sentinel, this is the quick solution.

Optimizing log storage and costs in Microsoft Sentinel is...