Visual studio doesn't recognize namespace inside same project - c#

The problem that i have is that when i open the solution that i am working on, in some files it will not recognize a namespace even thought that namespace is part of the same project and the solution builds fine. I could get rid of this problem by deleting my .suo file in the solution root folder but it is getting annoying to delete the .suo file every time i load the solution, plus i like the options that visual studio remembers the documents that i had opened when i closed the solution. I have heard that this may be caused by an extension but i disabled all the extensions and it still happens.
I am using visual studio ultimate 2013. I am working on a big solution that is connected with tfs and many peoples are working on it.
Does anybody have any idea why this is happening?

This question is old and I'm on a newer version of Visual Studio (2017), but having the same problem and my Google search led me to this question.
The solution to this in VS 2017 seems to be to delete the .vs folder that's in the same folder as the solution file. It's hidden, so you'll have to either show hidden files to see it or open a command prompt in that location and run the command
attrib -h .vs

Sometimes, if you have this problem and need a quick workaround, you can build .dll and reference that in project.

Related

Visual studio 2019 go to definition and Intellisense not working

I have noticed a weird issue with Visual Studio 2019 v16.0.1 the IntelliSense about "Using directive is unnecessary" normally grey is missing and type reference suggestion for missing using is not working.
I also tried with Visual Studio 2019 Preview but no luck.
I have tried the following:
deleted .vs folder and restarted.
Reinstalled Visual Studio
Reset settings via import and export setting under tools
Any other suggestions will be appreciated.
Close Visual Studio
Delete .vs folder (it is a hidden folder inside the folder which contains the solution *.sln)
Start Visual Studio
Solved my problem
Update From the comments
Deleting Browse.VC.db file within .vs folder worked for me. I did this to avoid deleting .suo which has information I want to preserve
NOTE 1: I am using Visual Studio 2019, but it may work on other versions
NOTE 2: This did not solve the OP problem, but it is a good candidate to solve your
Go to Tools -> Options -> Text Editor -> All Languages -> General. Make sure “Auto List Members” is checked. Also, make sure “Parameter Information” is checked.
If you are facing this issue with Unity projects then,
Check in your Unity settings whether it has Visual Studio configured as the external editor.
Click on Regenarate project files in the Unity settings.
Go to Assets => Open C# project.
This will restart Visual Studio with your project.
In my case, Resharper is the culprit. Disabling it immediately solved the issue.
I think these issues are discussed here and are resolved by an update and some worksrounds are bring discussed:
https://developercommunity.visualstudio.com/content/problem/505489/cannot-navigate-to-the-symbol-under-the-caret-3.html
For anyone who are searching for another suggestion, I just go throught this issue, as OP said, I've deleted .vs folder, I've update vs to last version, I've uninstalled and reinstalled vs to the last version, I've reset settings, delete all obj folders, I've installed Microsoft.Net.Compilers but nothing worked, at the end I just remembered that sometimes the projects required WindowsBase library, until now I don't know why, but after adding that dll Intellisense started to function again.
I use resharper (vs 2017) but had not installed it on 2019. After installing Resharper on 2019 the intellisense started working again. (yes, it was working in 2019, then stopped)
I don't have an explanation on why this would fix it. Just did for me.
First time I use VS 2019, I need to manually install Code Analysis. Make sure it is installed at your project properties.
And today, for the new class, the suggestion or namespaces not showing for VS 2019 Intellisense, and Go to Definition not working too.
I must do close solution, and re-open and VS 2019 doing scanning while opening project, and then worked again.
I think this is bug for VS 2019. Try to close solution and re-open it.
I have tried almost all the solution mentioned above but it doesn't helped me. Trying to restart my PC solved my problem.
I tried lots of things but nothing worked for me until I found this post. He mentions a few things I have already tried that didn't work, but his final solution worked for me...
At the root of our solution there is a packages folder. I deleted the
entire contents of this folder. Upon reopening Visual Studio,
Intellisense and Go To Definition were restored to full working order.
close visual stdio
For mac in your folder: do command + shift+ .
you will see hidden files -> delete .vs folder
open solution again
After working for a few months, Intellisense suddenly stopped. This cost me a lot of lost time! I've been worked with Visual Studio for about 10 years, and this problem happens occasionally in every version.
Here's what I tried for this iteration of the problem:
Closing Visual Studio and re-opening does sometimes make the problem disappear for a short time, but it certainly doesn't solve it
Likewise restarting my laptop
Installing the latest Visual Studio 2019 update didn't help (I'm on 16.8.3 now if anyone's interested)
Deleting the hidden .vs folder doesn't seem to solve anything (doing so also means you lose your current window layout, as well as any bookmarks you've set)
Unticking the Track Changes option in this menu: Tools-> Options-> Text Editor-> General.
I've updated my NuGet reference to the Microsoft.Net.Compilers library to the latest stable version, as suggested here, but sadly this made no difference
I thought I've finally solved the problem by following the advice from Homer. I deleted the packages folder at the base level of my project (somewhat nervously, as I wasn't sure if it was needed), and thought it had solved the problem, but no such luck.
However, one thing to watch out for - after doing this, Visual Studio recognised my classes but no longer recognised built-in ones (all the referenced namespaces at the top of my controllers were underlined in red). I then deleted the .vs folder (again), which seemed to solve the problem.
When I recompiled my solution, it gave a few CS0433 compilation errors with duplicate namespaces for the MinLength and MaxLength directives in some identity user name and password validation code. I got round this by removing the Microsoft.EntityFramework Nuget library (I had to also remove Microsoft.AspNet.Identity.EntityFramework too, since this depended on it), then adding them both back in, making sure to include at least version 6.2 of the former (otherwise I got another runtime error to do with the FirstOrDefaultAsync method called somewhere!).
My current situation: all existing Intellisense is working, but it's not recognising new classes I add unless I exit Visual Studio and go back in again. May have to live with this ... unless anyone can help me?
I've got that problem today with only one project. I got no Intellisense warnings (i.e. naming styles, "Variable not referenced", etc..) for files in that project. Not in VS 2017 Pro nor in VS 2019 Community.
Check, if your Project->Build->"Warning level" is set to 0...
If you have Visual Studio 2017 installed side-by-side with Visual Studio 2019, close VS2019, open the project in VS2017, wait until it is fully loaded, then close VS2017, and reopen VS2019 - fixed!
There must be a bug in the VS2019 intellisense stuff, but VS2017 seems to fix it with no need to keep deleting the .vs directory.

Why can't I load this solution in Visual Studio after the VS re-installation?

I am not so into .NET (I came from Java) and I have the following problem. I started a .NET project in Visual Studio 2017 Community Edition.
Then I uninstalled Visual Studio (because I obtained the exception messages in Italian language, so reading here I found that maybe uninstalling VS and installing it again with only the English language avoiding the Italian one it can solve the problem).
Ok, I reinstalled it selecting only the English language pack.
The problem is that now I can't open again my project in fact doing:
File --> Open --> Project/Solution
then I select the folder of my project then I select the .sln file of this project.
The problem is that the project is not loaded and into the Solution Explorer; I get the following error message:
Unavailable, the project file was unloaded
Here is what I see:
Why is this? What could be the problem? How can I try to fix and correctly load my solution?
"Unavailable" like that usually means it literally cannot find the project file.
Make sure the csproj is on disk, and at the locations specified in the .sln file.
Try running VS19 as an admin. It worked for me.
A project may be unloaded from Visual Studio to allow you to edit the project file, or to allow something else to modify it (as I suspect is the case here). You can do this by right-clicking on the project and selecting 'Unload Project'
To re-load the project, right-click on it and select 'Reload Project'.
Of course, if the project file is missing or damaged (as mentioned in the other answer) this may not work. If this is the case, try and find the .csproj file or edit it manually to see if you can fix what's broken.
Running as an Admin worked for me. I get this issue everytime I update my Visual Studio.
It's late but I faced this and i had to load all projects(option from context menu on solution)
Try opening the project only from the folder. This is: (Menu) File → Open → Folder. And not directly from the solution, which is: (Menu) File → Open → Project/Solution.

Project in VS2010 unavailable and can't reload

I've been trying to load a project from a SourceGear Vault Client that has a plug-in for Visual Studio 2010. After selecting the solution file, the solution explorer populates with the associated projects but appends (unavailable) to the end of each project name.
The usual remedy is to reload each unavailable project but in doing so briefly reveals all files within each project but then VS quickly hides them and makes the project unavailable again.
So far, I have tried opening the code in VS2015, removing all related source control information from the .csproj and .sln files, and deleting the associated .suo file. Nothing has worked yet and I have exhausted all the known fixes.
Thanks for your help.
For clarity, I'm copying #PeterRitchie solution that worked for me, below.
You could try running Visual Studio in safe mode to see if a 3rd party plugin is to blame: devenv.exe /SafeMode – Peter Ritchie

Cannot Edit .cs file in Visual Studio

I am facing a problem in editing .cs files in my project, I recently installed visual studio 2013 on a fresh operating system Windows 8.1 x64.
It is not letting me edit the Project files i created here,
I have read articles and Stackoverflow threads but every one here is referring to Resharper tools that i have not installed on my machine. so besides resharper tools cache clearing method, please suggest other solutions. Thanks!
EDIT:
Issue was resolved. Since, it was the fresh installation, I forgot to register the product before starting on it, After I had registered the product and it allowed me to edit files!
Close Visual Studio.
Open the folder that contains your .cs file, select the file and open it's properties. Remove any checked "read-only" or similar property.
Reopen Visual Studio and edit your file.

Visual Studio 2012 csc.exe Error. Executable not valid for OS

I am getting the following error when trying to compile and test any type of project in Visual Studio 2012 Professional.
Error 1 The specified task executable "Csc.exe" could not be run. The
specified executable is not a valid application for this OS platform.
After testing multiple suggestions online nothing has fixed the problem. Anyone know what is causing this? Is there a new version of Csc.exe I need to get a hold of? I know this is the compiler just not sure what I need to do to fix the problem.
I had this exact problem today on my Win7 Machine. As Hans suggests, 'Navigate to C:\Windows\Microsoft.NET\Framework\v4.0.30319 and type "csc".'
The file may still exist but if you can open it with notepad, it will probably show just plain text of some errors. This is the indication that your compiler has been destroyed. At my office we have come up with a theory that a Windows update may be causing this because only a few machines have been affected, but I haven't read much online about it until now.
We fixed this by copying someone else's csc.exe into the C:\Windows\Microsoft.NET\Framework\v4.0.30319 directory and recompiling. Be sure to set the options on the file to read-only so this won't happen again. Good Luck!
The problems associated with csc.exe in Visual Studio 2012 can mostly be solved by repairing Visual Studio.
You need to repair Visual Studio. Go to Control Panel -> Programs. Then select your version of Visual Studio you are using and press "Change"(or right click it and press "Change"). When the setup appears, click "Repair".
I am on Visual Studio 2017 but this is the first google result that pops up for "csc.exe not found"
When I got this error I had to restart Visual Studio, being sure to select 'Run As Administrator'. Everything worked after that
I've faced this problem while i am trying to move Asp.Net Mvc Project from one computer to another ; error message was : The specified task executable location "c:\users\mypcname\documents\visual studio 2015\Projects\TestMVC\packages\Microsoft.Net.Compilers.1.0.0\build\..\tools\csc.exe" is invalid.
I solved this by
Creating new Mvc Project ;
going to that folder \Microsoft.Net.Compilers.1.0.0\build..\tools
and Copied the csc.exe file to my Projets >> \Microsoft.Net.Compilers.1.0.0\build..\tools\
i think when i was copying the project from the original Computer i left that csc.exe file in the specified folder.
Hope this will help someone.
Check your solution properties (right-click on Solution and select 'Properties') and make sure that the 'platform' field (Configuration Properties) is set correctly.
I think this problem is caused due to improper PC clean up. I was running Quick Heal PCTuner 3.0 software on a 64-bit windows 7 machine but suddenly due to loss of power my machine was shut down then when i opened it again I was getting this problem in VS 2013. Even TortoiseSVN checkout was not working and throwing internal error and something like corrupted disk also was shown when trying to delete some files on the harddisk.
I ran the PC Tuner again doing the Disk, Registry and traces clean up and it got fixed. maybe this problem may occur due to other cases also but is mostly related to the system's files In my case this is the fix
Regards.
in my case helped (I had .net framework 4.5.1 and vs c# 2010 express):
download the newest .net framework and run repair
On Visual Studio 2013, the same problem solved by doing this for me:
Right click the solution and open Configuration Manager. For the project(you may see at least one there), I've changed the Platform from Any CPU to x86 for the project that may causing the problem.
I've tried to delete and move csc.exe file but it doesn't do anything.
Then simply I upgrade .net version and than downgrade (returned to its original state) and it works.
I solved my problem by copying the whole folder containing my visual studio solution
From C:\Users\me\Google Drive...
To: C:\Users\me\OneDrive...

Categories