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:
- 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.
- Fix nugget, enter in the nugget console
and execute Nuget restore SolutionName.sln
- 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.
- 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.
Heyho, THX for that hint!
I faced today the same problem, after hours of rebuild, FW switches i found out that it was simply a renamed enum field… The compiler doesn’t throw an error, the Code Analysis too. So in my case, after changing the reference to the enum, the error was gone.
It solved my problem by unloding and rebuilding individual project.
Oh man, thanks for this post! I’ve been struggling with this for hours. It turned out to be a new Class Library I added. Visual Studio 2019 (understandably) chose the latest version of .NET (4.7.2) but the main application consuming the DLL was using 4.5. The compiler error is completely unhelpful…but this blog saved the day! :o)
Thanks for writing this. I faced the same issue and was able to resolve after restoring packages from command line instead of VS.
Good article! I would add one more item: Missing installed certificate will through same error.