Visual studio cannot find my referenced DLL's namespace
Asked Answered
L

7

16

This is a very frustrating problem. All of a sudden I cannot use referenced DLLs. I added an assembly reference to a project in the same solution and the namespace is unrecognised. I can even see the reference in the object viewer. I've also changed the projects to .NET 4 and 3.5 without the client profile to no avail.

Lefebvre answered 1/5, 2012 at 17:32 Comment(7)
The most likely cause of this problem is the referenced DLL is itself invalid. Have you tried loading it in reflector to see if it contains members?Dragrope
did you download it from the internet? if yes, did you "unblock" it in the file properties?Diphyllous
Are both projects built to the same .NET Framework version? What happens when you build just the referenced project? Can you see the dll in the bin?Mcmullin
No it's my own DLL, which builds perfectly fine with no warnings or errors. All projects are set to .NET 4. How do I view its members in the reflector?Lefebvre
There have been several times where deleting the bin and obj folders and then rebuilding solved VS weirdness that made no sense.Tintometer
OK I'll give it a go. Here's a screenie showing the DLL imagebam.com/image/8f730f187884338Lefebvre
Hmm deleting those didn't work either. I moved this solution to a new folder but shouldn't rebuilding solve any dependencies?Lefebvre
E
35

Based on your screenshot, you have references to the same "ServerLibrary" DLL in multiple projects, however, it looks like one referenced version is compiled in .NET 3.5 and the other referenced version (the project reference it appears), is compiled in .NET 4. Make sure all projects point to the same version of the DLL and recompile all. That should fix your problem.

Electrify answered 1/5, 2012 at 17:58 Comment(6)
Thanks. I discovered the same problem when I referenced a server DLL project from a console app in VS2010, even though all projects where using .Net 4.0. Switching the Target Framework in the console app from ".Net Framework 4.0 Client Profile" to plain old ".Net Framework 4.0" resolved the error.Visually
@Visually please mark his Answer as "Answer" if he solve your problemIridize
Same problem here, apparently same cause. BUT I could not solve it by setting the .NET version (in my case 4.5.x to 4.6). I removed the project, added a new one, set the version correctly from beginning and voila, it worked. Are they offering assembly referencing boot camps? Like a death camp of assembly referencing? I'd be interested.Hogback
THANK YOU. Just struggled with this for several hours before realizing that I had a reference compiled with .NET 4.5 in a .NET 4.0 project. I love that I could be your 25th upvote. Enjoy the silver!Talkie
In similar situations, you make get a version conflict warning, but not in the case. solved!Benia
It worked for me. Problem came when I was trying to use my library in a project that was targeted to a lower .NET version than the library.Clicker
D
13

I faced this problem, and I solved it by closing visual studio, reopening visual studio, cleaning and rebuilding the solution. This worked for me. On some other posts, I have read the replies and most of users solved the problem by following this way.

Dog answered 19/10, 2015 at 6:17 Comment(3)
I found the same to be true. Had to shutdown and restart VS 2015 Update 1. The reopen solution, clean and was only then able to see the referenced assembly.Ably
@Ably I am glad to see my reply is helping people. please upvote my reply.Dog
i only restarted visual studio 2017, the problem was fixed.Sconce
C
1

I removed DLL name and namespace from the path where I was using it. And for some wierd reason it worked.

Clue answered 10/10, 2018 at 18:52 Comment(0)
L
1

Make sure that the classes are public classes too. I had this issue when I couldn't find my model classes. Silly mistake but frustrating when unnoticed.

Leotaleotard answered 13/8, 2020 at 16:43 Comment(1)
Well done. This was the answer for me.Roomer
W
0

This is mostly cause becauese of using diffrent version of same packages at diffrent projects at same solution. I recommend to update all packages to lastest version at all projects.

Right click to project that has downgrade packages --> manage nuget packages --> click the updates tab --> check the 'select all packages' checkbox --> click the update

Do this for all prjects at solution.

Whole answered 8/10, 2019 at 13:10 Comment(0)
H
0

I had this problem using Visual Studio 2019 with Resharper. I resolved it by clearing the Resharper cache.

Extensions\Resharper\Options General Page "Clear caches" button.

After clicking "Clear caches", I restarted Visual Studio and did a Clean/Rebuild.

Headwards answered 31/5, 2022 at 2:42 Comment(0)
R
0

VS2019 July 2022: I had to deal with same issue for more than a day.

The comment by JaredPar helped to resolve it :"most likely cause of this problem is the referenced DLL is itself invalid. Have you tried loading it in reflector to see if it contains members? –

So If you reference an assembly and IT DOES NOT CONTAIN at least ONE public type(Class, Property ,Enum, .. etc) still it does not show after the using keyword. This behavior makes 100% sense, because what is the point of referencing something which is useless? However Microsoft could easily have added a Message/Warning in VS to make the life of the developer less Miserable.

Something like "Warning: Reference ABC does not contain any public members"`

Roomer answered 20/7, 2022 at 18:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.