83

I have a solution with 3 projects:

  • ParsersBase, that defines an interface IParseRule
  • ParsersLibrary, that has a reference to ParsersBase and defines a class HtmlImageUrlParseRule : IParseRule
  • ParsersLibraryTest, that has a reference to ParsersBase and ParsersLibrary and defines a test class with some test methods

When I'm trying to build it, I get a warning:

Reference to type 'AVSoft.ParsersBase.IParseRule' claims it is defined in 'c:\Users\Tim\Dropbox\projects\Image Downloader\ParsersLibrary\bin\Debug\ParsersLibrary.dll', but it could not be found

Why is VS trying to find AVSoft.ParsersBase.IParseRule in ParsersLibrary.dll? ParsersLibraryTest has a reference to ParsersBase; it just doesn't make any sense.

0

18 Answers 18

40

Another way this could happen is if you're using several NuGet packages where one, probably central, package has been updated but some additional functionality packages haven't been.

To work through my recent example - the error was "Reference to type 'ConsumerSubscriptionConfigurator<>' claims it is defined in 'MassTransit', but it could not be found". This is because we had updated MassTransit from 2 to 3, but we had not updated some of the other optional packages (MassTransit.log4net and MassTransit.Autofac) to the same version number. It appears as if assembly redirection had kept everything working until we tried to use one more additional feature.

4
  • 1
    I had conflicting versions of Microsoft.Bcl.Build installed in my projects. A good way to check is to go to manage nugget packages for solution and see if you have mismatched versions. Microsoft have gotten better at detecting this now with a specific warning for certain mismatches like their htt
    – rollsch
    Commented Jul 12, 2017 at 23:32
  • I had similar error "Reference to type 'ISagaConfigurationObserverConnector' claims it is defined in 'MassTransit', but it could not be found" - updated MassTransit to latest version and forgot to update MassTransit.MassTransit.AzureServiceBus resulting in this error - solution was to update all packages related to MassTransit
    – Binu
    Commented Apr 19, 2018 at 18:55
  • In my case, it was when I updated Hotchocolate from stable to latest previews, main package was updated but Hotchocolate.AspNetCore wasn't.
    – Milad
    Commented Oct 5, 2022 at 21:39
  • For me, it was caused by a NuGet package that referenced another NuGet within the same NuGet-solution through NuGet.org (using an older version) instead of using a project reference (which guarantees the latest version). It was confusing because the NuGet projects build and pass all tests but the consuming solutions started throwing this error.
    – Napoleon
    Commented Jan 7, 2023 at 17:05
35

This error seems to cover a variety of scenarios. In my case, closing and re-opening Visual Studio was the trick. After restarting Visual Studio, I was able to build the project as expected.

3
  • 2
    Along these lines, I simply built the solution and it went away taking its red squiggly lines with it.
    – ouflak
    Commented May 12, 2018 at 19:53
  • 20
    Amazing how many problems are solved by simply restarting VS. This is the top answer in 50% of VS problems. Commented Jun 29, 2018 at 11:56
  • The usual helped, dotnet nuget locals all --clear, git clean -xfd, restarting...
    – Kiechlus
    Commented May 12, 2023 at 13:07
17

I had a similar problem. The site was running a cached version of the dll and not the one I had deployed to the bin directory. I cleared the temporary asp.net folder contents and this solved the issue.

2
  • I seemed to have a similar issue. To find the culprit I built each project separately one by one, and it turned out to be an asp.net project that was having the issue. Removing and re-adding project references from/to the asp project fixed it. Commented Mar 4, 2015 at 21:13
  • Where is the temporary ASP.NET folder? Never mind ... C:\Users\User\AppData\Local\Temp\Temporary ASP.NET Files
    – JDandChips
    Commented May 27, 2020 at 10:32
17

It was my fault, I had a ParsersLibrary project at the start and then renamed it to ParsersBase, but I didn't rename an assembly name, then I added a ParsersLibrary project again.

So, two projects had the same assembly name and it's not very good, is it? :) Assemblies overlap each other, so I have this error.

0
7

I had the similar problem: Reference to type 'Func<>' claims it is defined in 'mscorlib', but it could not be found. The problem was following: my solution had Target Framework = 3.5 and I added a reference to Microsoft.Practices.Prism v 4.0 which is built against the framework 4.0.

After changing target framework to 4.0 it worked

1
  • In my case a lib was newer (4) than the app (3.5) and the lib has added a signature with Func<T>
    – Robetto
    Commented Feb 21, 2019 at 9:17
5

It looks like things are a bit easier now than they were before.

As other answer(s) have basically already stated, this error can result from an older version of the same NuGet package not having some of the newer types in it. While in production, this is generally managed through proper versioning, in development, you may end up reusing the same version number when making changes. And that's a likely place where this problem can arise.

To fix this, you can often just clear the cache by doing the following:

  1. In Visual Studio, go to Tools > NuGet Package Manager > Package Manager Settings.
  2. In the pop-up menu, navigate to NuGet Package Manager > General.
  3. In the options on the right, click Clear All NuGet Cache(s).
3

I hit this exception today. The problem in my case was I had some.package v2.1installed in my host and some.package v2.3 installed in other projects. Update-Package on the host project to v2.3 fixed the issue.

3

I my case, I tried to test a WPF project with a .NET Core (3.1) test project which could not reference the needed WindowsBase.dll.

1

Updating/consolidating packages didn't help. Even a clean repo and a restart of Visual Studio didn't solve it for for me.

But rebooting did fix the problem!

1

@binki's comment helped me;

deleting all .vs, bin, and obj folders, and then reopening the project

0

ParsersLibraryTest needs to reference ParsersBase. The second part of the error should read "You must add a reference to assembly 'ParsersBase..."

3
  • As I wrote before, ParsersLibraryTest have references to ParsersBase and ParsersLibrary. But there are interesting thing: I can't use namespace, that is declared in ParsersBase in ParsersLibraryTest project. When I remove reference to ParsersLibrary there, that namespase turns to be avalible, but it's useless, because I obviously need ParsersLibrary in this project too. Commented Oct 20, 2013 at 6:48
  • If you can't use the namespaces and it doesn't compile the project is probably not referenced correctly. Try redoing the references perhaps?
    – Slugart
    Commented Oct 20, 2013 at 8:23
  • I found the exact opposite problem. When I deleted excess references to items found deeper in the nuget dependency tree, the error went away, it used the dependency tree. Commented Feb 13, 2023 at 15:18
0

I tried all of the above answers but none resolved my issue.

In the end, I checked in my latest code (GIT), then recloned the repository in a different location.

Not ideal, but at least problem solved.

1
  • 3
    You could probably get away with closing VS, deleting all .vs, bin, and obj folders, and then reopening the project. Sometimes that’s faster than dealing with re-cloning and reconfiguring.
    – binki
    Commented Oct 19, 2018 at 22:29
0

I had the similar problem: Reference to type 'Func<>' claims it is defined in 'mscorlib', but it could not be found. I have a lib of .Net 4 that was referenced by a .Net 3.5 program. After upgrading both to 4.61 it worked.

Seems like Func<T> is missing in .Net 3.5 and just upgrading that sample app would have been enough.

Further exp: Someone had added a signature in the library project (.Net 4) that uses a Func<T> parameter. But the sample program (3.5) already existed and ran fine so far. But at time of recompilation a dependency of a dependency clashed. Because mscorelib-3.5 had been already loaded. All happens at compilation time.

0

The only way I could overcome this error was to force uninstall of all nuget packages related and then reinstalling them. Sad but true.

0

I've just struggled with this error for a while now and finally get around it. This is how to re-produce it and how I fixed it.

The problem was: The packages were referenced by Right clicked -> add refernece -> Browse (choose). Then were added again as NuGet packages.

The solution was:

  • Remove the added references.
  • Remove the installed packages from .csproj.
  • Re-install the required packages from NuGet package mangager.
  • Close Visual Studio and re-open it.
  • Clean Project.
  • Build Project.

Note: If you couldn't remove the referenced files (no Remove option on right click) try close Visual studio and re-open it. Or delete or move the dll that were referenced then try again.

0

For me, I had chosen incorrect project, I was creating a class library project, I had to chose "Class Library (.Net framework)" but I had chosen "Class Library (.Net standard)"

Replacing the same resolved the issue.

0

The problem was following: my solution had Target Framework = 3.1 and I added a reference to Microsoft.EntityFrameworkCore.SqlServer v 2.0 which is built against the framework .

0

I had this problem with one of my library projects inside of a solution, after I switched from .NET Framework to .NET Standard. Eventually I just removed the project reference and added it again inside the application project that was reporting the problem. Oddly enough, the only thing that changed was project GUID switching to lower case from the previous upper case.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.