Visual studio cannot find my referenced DLL's namespace - c#

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.

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.

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.

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

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.

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.

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.

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"`

Related

Warning on dependencies when create a new standard .NET project

I have installed VS 2017 and I am sure all features related to.Net Framework, Core, C#, and ASP.NET are installed with others.
All I do is create a new project (.net standard class library) then the dependencies section is showing the warning (yellow triangle) sign. When I click on the dependencies visual studio freezes and close. If I try to work with any library I get the same error
cannot resolve symbol
Any ideas please?
When I try to build the solution, I get the following error
EDIT
I have also checked NuGet Package manager and found that the available source looks like below
Well, What I am going to say will sound CRAZY, but it is a fact and known issue and really hard to be found.
The problem is in the project path, the path for the project I have created contained a special character c:/users/Hussein Khalil(XXX)/PROJECT_NAME
when I created the project on a simple path c:/test/... everything is worked fine.
Hope this could help.
I faced the same issue and it was not related with special characters in project path.
I executed "clean solution" and then "build solution" and it restored the dependency successfully. It solved the issue.

Only c# native classes are recognized

I migrated a silverlight 5 project from vs2013 to 2015 (both professionnal edition).
This is not even a real migration, because there is nothing to change in the code, or configuration, and Visual Studio say nothing when opening the project with 2015 instead of 2013.
The weird thing is, in VS 2015, my classes are not recognized in the code, and so, I cannot use completion.
As you can see in the code below, the word RivoliView is still black, because it is not recognized like DemView. The consequences are, I cannot use adresseBDUChild and access it's properties, while RivoliView is in the same namespace and a public page (the same way that DemView 'public partial class), and therefore, should berecognized.
In fact, all the classes that are not c# native (by native I mean like int, string List<T>, Boolean) are not recognized there, whle it was in studio 2013.
I cannot access properties from my classes, cannot have autocompletion.
What happened?
The project compile perfectly, and work perfectly when running in debug in the browser. It works excalty the same way it was in vs2013. But the problem here seems to come from visual studio.
I tried to get the project directly from Team Foundation server. Nothing.
Tried clean, rebuild, build, deleting .pdb files etc... No errors, but change Nothing. It always run as it should, without probems. Still not recognized.
Is it a vs2015 configuration problem?
The namespaces are well defined, and used in the page. This is weird since the same code recognized this classes in visual studio 2013.
Any idea?
I hope my question contains all useful details that I thinked about. If I forgot, tell me how I can be more specific.
Edit : still searching, and got no clue. I think I will go back in 2013 if I can't find an answer.
Now I also tried :
EDIT > IntelliSense > Refresh Remote References
removing and re-adding project references, such as Microsoft.CSharp.
Adding and removing the project from solution.
Creating new solution and then add the projects.
Thank you.
Try to refresh IntelliSense cache
EDIT > IntelliSense > Refresh Local Cache
and/or
EDIT > IntelliSense > Refresh Remote References
It sounds funny, but you might want to try removing and re-adding project references, such as Microsoft.CSharp.
That can often give VS2015 the kick it needs to re-analyse the project.
Edit:
When I say remove and re-adding, I mean via References under the Solution explorer.
Open references, right click on Microsoft.CSharp, and choose remove.
Add a new reference, go to Framework and find Microsoft.CSharp and add it.
It seems to make a difference for me when I do this manually without using Resharper or Visual Studio to resolve the reference for me.

Visual Studio & Circular Dependency woes

I have a legacy system that's made up of 15 different projects and when I've tried to reference one from the other Visual Studio complains that it cannot do so as that would cause a circular dependancy.
My problem is that I can't see how it would cause a circular dependancy as the project I'm trying to reference ('XScript') doesn't have any sort of refence to the project that's trying to reference it ('WPF_Forms').
From researching around on here I've found people suffering similar fates though their problems seem to have obvious circular dependencies.
I've downloaded a demo copy of NDepend as recommended on a few posts from here and despite working through the various dependency tools on there there's still no obvious link.
I've right-clicked on the projects involved and used the "Project Dependencies" option but I can't see any link. I've also re-started Visual Studio and tried "Clean Solution" and "Re-build Solution" to no avail.
The only way round that I've been able to come up with is to reference 'XScript' by referencing the built DLL and not the project itself, however that feels a bit dirty and I want to know why this is happening rather just hack round it.
Can anyone suggest anything I may have missed or any strategies I could employ to work out what's going wrong?
EDIT 1 : XScript used to reference WPF_Forms but that reference has since been deleted (and the project cleaned and rebuilt with no dependencies showing on the 'Project Dependencies' window. I suppose it could be possible that VS has retained a link somewhere or that it thinks the projects are linked somehow.
EDIT 2 : Following on from BitBonk's suggestion I've ran used VS's Code Map feature and worked out the project topology. XScript and WPF_Forms are only referenced by the main .exe and nothing else. I'm beginning to suspect this is a VS issue and I may have to create a new project and add all the sub-projects in again to get it working.
And the problem was: Visual Studio 2012.
After using Code Map like Bitbonk suggested I could see no references that would cause the problem. So, I removed both XScript and WPF_Forms from the project, ran a clean, added XScript back in ran a clean and then added WPF_Forms back in and ran a clean.
After that adding the reference from WPF_Forms to XScript didn't cause any problems. I can only guess this is a bug in VS that was triggered by it not recognising there was no longer a dependency from XScript to WPF_Forms.
Hopefully this question and the suggested answers will help someone else in future.
As already stated by others your circular dependency might involve multiple levels. You can easily visualize the dependency graph using the code map feature of viusal studio 2012. That way you might be able to spot where this would happen.
Maybe your circular dependency involves more than 2 projects.

Visual Studio 2010 issue with a class that doesn't compile

I have a Visual Studio 2010 C# webforms solution with various projects in it. There is a certain class in one of them that acts strangely. If I open some code in another project and then use the "go to declaration" command to get to the class in question, Visual Studio shows me meta data from the DLL instead. However, if I do the same for another class in the same project (while still using "go to declaration" from another project), I get to the actual code just fine.
Same thing happens when I try to compile. I alter code in this class to no avail, Visual Studio simply doesn't compile the changes. Again only for this one class, all the rest seems to work just fine.
Using "go to declaration" from inside the same project works.
I believe this was caused by our upgrading the solution from .net 3.5 to 4 recently, which brought about a variety of issues that we were able to fix though. This particular issue only seems to exist on my own machine currently, as the code in question is still in development and not checked in yet.
I don't think it matters, but for the sake of completeness: the class in question is an interface.
I've tried "clean solution" and deleted a variety of Visual Studio cache files, nothing seems to have helped so far. Any possible solutions very welcome.
It might be a problem with your references - it may be referencing the compiled assembly instead of the project.
Try deleting each reference to that assembly and add them back in as project references.

Visual Studio 2010 suddenly can't see namespace?

My C# WinForms solution has two projects.
A DLL which is the main project I'm working on, and an executable WinForms I call "Sandbox" so that I can compile/run/debug the DLL easily in one go.
I'm working in .Net 4.0 for both projects.
Everything was working fine until I added some seemingly innocent code, and a reference to System.Web in the DLL.
Now my Sandbox project can't see the namespace of the DLL project. I didn't change anything which I believe should have affected this.
If I delete the project reference to the DLL from the Sandbox references and re-add it, then the red underlines all disappear and the colour coding comes back for all my classes etc; but as as soon as I try to build the solution, the whole thing falls apart again.
When I right-click the DLL project in the Sandbox's references and view in object browser, I can see the namespace and all the stuff in there.
I have a feeling this might be some sort of bug?
Is this some sort of VS2010 bug? I had this same issue a few months ago and I could only fix it at the time by making a whole new project and re-importing my files. This time, however, I have a bajillion files and will only do that as a last resort!
Edit:
After panickedly going through and undoing all my changes, trying to find what caused the problems, it seems to be this line:
string url = "http://maps.google.com?q=" + HttpUtility.UrlEncode(address);
If I comment out this line, then I get no namespace errors and the project builds fine. I can't see anything wrong with this line though.
I'm ready to declare this a bug in VS2010, this has bitten way too many programmers already. The fix is easy: Project + Properties, Application tab, change Target Framework to ".NET Framework 4" instead of the Client Profile that is selected by default.
System.Web is not included in the client profile. Having this option in the first place is quite silly, the client profile is only 15% smaller than the full version of .NET 4.0. Having it selected by default is even sillier. But I digress.
UPDATE: mercifully this all got fixed in VS2012. Which no longer makes the client profile the default for a new project. And the client profile got retired completely in .NET 4.5, good riddance.
Check to make sure that both projects are using the non-client profile for their target framework (go to each project's properties to do this).
One possibility is that the target .NET Framework version of the class library is higher than that of the project.
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.
Try building only the project with the Sandbox dll first independently.
Then point your executable project to the required dll and ensure copy local is set to true. in reference settings.
Tthen build the executable project.
Changing the target framework from the ".NET Framweork 4 Client Profile" to ".NET Framework 4" worked for me with a similar problem. I agree that the client profile doesn't seem to have much of an advantage to using it. I seem to get nailed with weird errors that I hunt for until I remember that Visual Studio defaults to the client profile. I guess the moral of the story when getting an error is: if "Rebuild Solution" doesn't work, check the Target framework...
If you tried already doing the Framework change, and still not worked, I hope this works for you (as it did for me): Simply add the necessary references from within your projects. Very obvious but I was doing it wrong until I found what was the issue.
I just had this issue and it turned out to be I had multiple namespaces being used that had the same object name (i.e. business objects had the same names as mvc models);
Fully qualifying the names fixed the issue for me.

Categories

Resources