Visual Studio refuses to build project due to missing assembly reference that isn't missing
Asked Answered
G

7

35

I'm building a c# windows service and has added a couple of assembly references (to other projects of my own) to my project.

I get the following error when I build:

"Error 25 The type or namespace name 'TestClass' could not be found (are you missing a using directive or an assembly reference?"

Interestingly enough, the reference path in the csproj-file is correct, and on top of that, classes and namespaces from the referenced project, that according to Visual Studio is missing, is being picked up by Intellisense and even the "go to definition" function works fine. Furthermore, I have other projects in the exact same folder as my new windows service and they picked up the assembly references just fine. All the referenced projects are included in the solution.

I use Visual Studio 2013 Update 3. There is really no code that I could show that would give you more information, but let me know if you want to see some screenshots or something.

Attempts so far:

Update When I select one of the "missing" references in the reference list, and go to properties, there is no path defined. Yet, the relative path is in the csproj-file as is correct. Confusing.

Update 2 Removing all the references, reloading the projects and then doing a clean fixed it for me. Apparently, the problem was caused by all dlls not being updated in the build stack.

Gal answered 30/4, 2015 at 8:12 Comment(7)
Have you tried removing and readding the reference?Petit
What are the target frameworks of the reference and your project?. The project target has to be equal or higher then that of the referenceNode
did it happen after you changed the dll's after adding them and then tried to remove and add again ? this seems to happen in this scenario.Irmgardirmina
Did you already compare the references in your .csproj to a "good" project's .csproj?Verecund
The framework versions are the same. I have tried removing and readding the references. I've compared the references in the "healthy" projects. The text is literally identical.Gal
A few other possible solutions: #451499Similar
Yes, I tried those solutions but they didn't help. This guy did not get Intellisense-references so I believe his problem was different. My problem, however, is solved now!Gal
I
14

1.remove all references

2.Build --> Clean solution

3.Clean your project using this project as sometimes visual studio fails to clean everything neatly.

Irmgardirmina answered 30/4, 2015 at 8:23 Comment(3)
I tried removing every single reference, then did a clean. It seems to have done the trick. Thanks!Gal
I have to wait a couple of minutes before I can accept it. I will when I can.Gal
If you received a solution from a 3rd party, check your solution and the 3rd party solution are the same .net framework versions. Was my problem and a simple change of version did the trickOralla
J
36

In my case, target Framework of Assembly Project and the target Framework of the project where i want to use this assembly are different. Target framework of assembly project was 4.5 and target framework of my project was 4.0.

When I have change the target framework of my project to the target framework of assembly project i.e. from 4.0 to 4.5 , it works fine.

For change the Target Framework of project,

Right Click the project -> Properties -> Application -> Target Framework

This Target Framework is drop-down list, select your required Framework from this list.

Judsen answered 21/8, 2017 at 13:9 Comment(0)
I
14

1.remove all references

2.Build --> Clean solution

3.Clean your project using this project as sometimes visual studio fails to clean everything neatly.

Irmgardirmina answered 30/4, 2015 at 8:23 Comment(3)
I tried removing every single reference, then did a clean. It seems to have done the trick. Thanks!Gal
I have to wait a couple of minutes before I can accept it. I will when I can.Gal
If you received a solution from a 3rd party, check your solution and the 3rd party solution are the same .net framework versions. Was my problem and a simple change of version did the trickOralla
U
8

Reinstalling packages worked for me.

From the Package Manager Console, run the the following command to reinstall all packages.

update-package -reinstall

You can target a single package with:

update-package PACKAGE_NAME -reinstall

Ultima answered 12/9, 2019 at 14:52 Comment(0)
B
4

Another possible issue could be mismatch in targeted versions of .NET between the assemblies. I experienced the same symptoms and setting the same version of framework did the trick for me.

Boxing answered 21/8, 2017 at 8:0 Comment(0)
S
2

I think you are missing a Nuget Library called: Bogus. You can install it from Nuget-Solution installer in visual studio. Just install it and also add using Bogus.DataSets; on your class file. Hopefully this will solve your issue.

Spruik answered 21/7, 2020 at 6:20 Comment(0)
B
0

I the same problem. Or at least the symptoms were same. My solution was located on a network drive. Moving the solution to my local drive solved the problem for me.

The reason was apparently that Windows 10 didn't see the network drive as a trusted enough location. It worked fine until I managed to break my solution somehow. Visual studio apparently didn't have the required rights to perform needed the fixing operations.

Bailsman answered 20/6, 2019 at 10:48 Comment(0)
C
0

I faced a similar issue: the compiler complained about a missing assembly reference, even if it was in the csproj file.

Error without the reference:

error CS0246: The type or namespace name 'IMyService' could not be found (are you missing a using directive or an assembly reference?)

So I added the reference:

<Reference Include="My.Library, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
  <SpecificVersion>False</SpecificVersion>
  <HintPath>path/to/lib/My.Library.dll</HintPath>
</Reference>

And got a slightly different error:

error CS0012: The type 'IMyService' is defined in an assembly that is not referenced. You must add a reference to assembly 'My.Library, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.

Even after updating the reference to match the exact string from the error message, I still got that second error.

The problem was that I was mixing signed and unsigned assemblies. My project architecture was roughly this:

  • A.dll - unsigned assembly
  • B.dll - signed assembly; references A.dll; compiles OK
  • C - references A.dll and B.dll; individual references OK; get errors above when calling a method in B that returns a type from A

I fixed my issue by signing the assembly ("A" in my example above). I did this by referencing the StrongNamer NuGet package.

Cnut answered 28/1, 2021 at 14:17 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.