Reputation: 1294
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 methodsWhen 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.
Upvotes: 84
Views: 115822
Reputation: 5657
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.
Upvotes: 0
Reputation: 155
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 .
Upvotes: 0
Reputation: 4750
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:
Tools > NuGet Package Manager > Package Manager Settings
.NuGet Package Manager > General
.Clear All NuGet Cache(s)
.Upvotes: 5
Reputation: 165
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.
Upvotes: 0
Reputation: 10100
@binki's comment helped me;
deleting all .vs, bin, and obj folders, and then reopening the project
Upvotes: 1
Reputation: 2989
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.
Upvotes: 3
Reputation: 138
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!
Upvotes: 1
Reputation: 1655
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:
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.
Upvotes: 1
Reputation: 10213
The only way I could overcome this error was to force uninstall of all nuget packages related and then reinstalling them. Sad but true.
Upvotes: 1
Reputation: 789
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.
Upvotes: 0
Reputation: 771
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.
Upvotes: 0
Reputation: 171
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
Upvotes: 7
Reputation: 818
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.
Upvotes: 35
Reputation: 6943
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.
Upvotes: 41
Reputation: 1294
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.
Upvotes: 17
Reputation: 33098
I hit this exception today. The problem in my case was I had some.package v2.1
installed in my host and some.package v2.3
installed in other projects. Update-Package
on the host project to v2.3
fixed the issue.
Upvotes: 3
Reputation: 356
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.
Upvotes: 18
Reputation: 4680
ParsersLibraryTest needs to reference ParsersBase. The second part of the error should read "You must add a reference to assembly 'ParsersBase..."
Upvotes: 0