VS 2019 Console.WriteLine() versus System.Diagnostics.Debug.WriteLine() - debugging

In Visual Studio 2019 I'm unable to get System.Diagnostics.Debug.WriteLine() to show anything in either the Output(Debug) windown nor the Immediate Window. I've got my options settings for 'Debugging->General->Redirect All Output Windown Text to the Immediate Window' unchecked.
I'm able to see the output of Console.WriteLine in both the browser console and the VS Output window.
My code is a multiproject one with Blazor and razor classes.
I'm looking for a super simple explaination as I've been searching Google trying to find the solution for an hour now and nothing is helping.
Thanks in advance!

I did not have the same situation as you described in my side.
And you should check your Vs environment or try the following steps:
1) disable any vs installed extensions under Extensions-->Manage Extensions-->Installed to check if there is an extension caused that.
2) reset all settings under Tools-->Import and Export Settings-->Reset all settings. And you can also make a backup about your settings
3) use devenv /safemode under Developer Command Prompt for VS to start a pure VS and then test your project there.
4) close VS, delete .vs hidden folder under the solution folder, bin and obj folder, then restart your project to test it. Besides, you can also create a new project to test whether the issue happens on a new project.
5) make a initial to your VS, close VS, rename C:\Users\xxx\AppData\Local\Microsoft\VisualStudio\16.0_xxx to another name, and it stores all your current settings and environment of VS. Renaming it is equivalent to making a backup. Then, restart VS.
6) repair VS or update it to the latest version if there is a new update.
Besides, you can also share a small sample about your project to help us troubleshoot the issue.

Related

Blazor or Visual Studio error when assigning value to variable

Not sure if I'm the only one seeing this in Visual Studio 2019 with Blazor. But if you set a variable and then assign a value to it later, it automatically enters the variable name after you enter the "=" sign.
private string _test;
_test =_test
Am I missing a VS setting? Not sure if this is unique to Blazor or VS2019.
Found the culprit. By taking Perry's suggestion of toggling each Extension, I found the one that was causing the issue. Took quite awhile because I have a number of extensions.
It seems the CSS Tools 2019 https://github.com/madskristensen/CssTools was the issue.
Confirmed it by turning it enable/disable a number of times. I now keep it disabled and have no issues.
Actually, I have not faced the same issue in my side.
So I doubt whether it is caused by your project itself, vs settings or vs extensions.
You could try the following steps to troubleshoot the issue:
Suggestion
1) disable any vs third party installed extensions under Extensions-->Manage Extensions-->Installed then restart VS to test it.
2) reset all vs settings under Tools-->Import and Export Settings-->Reset all Settings
3) close VS, delete .vs hidden folder under the solution folder, any bin and obj output folders and then restart your project.
4) repair your VS or update it if there is a new version.
Besides, you can also provide a screenshot about presenting your issue.

CodeLens not showing references

CodeLens stopped working for some reason in project solution that I'm dealing nowadays. It is not showing references instead "- references". However, when I open up Visual Studio with another project It works like charm.I can confirm that CodeLens is enabled. Do you have any idea to make it work?
My Solution:
Toggle the CodeLens feature off and then on again.
Note: Many have found the feature to be turned off after an update so you just need to turn it back on. Thanks to #razblack for calling this out. Don't forget to give his comment an upvote if this was your issue!
Go into Tools -> Options... -> Text Editor -> All Languages -> CodeLens.
Uncheck "Enable CodeLens" option and click OK.
Go back into Tools -> Options... -> Text Editor -> All Languages -> CodeLens.
Check the "Enable CodeLens" option and click OK.
Note: I've fixed the issue once before by closing the problem .cs file and then reopening it. Closing any referenced files may also be required.
My Problem(s):
Similar to the original poster, CodeLens stopped refreshing references after I made a bunch of refactors. I was seeing stale references to code that didn't exist and I was also seeing the "- references" issue as described in the original post.
My Environment & Specific Scenario:
Visual Studio 2015 with Service Pack 2 and Resharper Ultimate 10.0.1
I was doing a major overhaul with a ton of refactoring and my project wasn't compilable for an hour or so. Once I could compile the project again, the references weren't working.
Same problem here.
CodeLens works normally with small solutions, but not working with large ones.
And this behavior is accompanied with crash of Alm.Shared.Remoting.RemoteContainer.dll process.
Tried in VS 2013 Update 4 and VS 2013 Update 5 RC.
Solution:
Close all programs and clean %LocalAppData%\Temp folder (or maybe just ALM folder inside it).
A simple solution, which works!
I did try enabling CodeLens in Visual Studio (2015) -->
Quick Launch (Ctrl+Q)
Options (CodeLens)
But, it was enabled :( Then, it did work with: (Closing the programs),
Win+R --> %temp% EnterDelete all
For me, CodeLens was disabled, so make sure it is still enabled.
I know it is an easy answer, but it might help some developers.
Go to Tools -> Options -> Text Editor -> All Languages -> CodeLens then click the "Enable CodeLens" option if it is not checked and then save it.
It looks like VS disabled it for some reason, maybe after an update or slow startup.
Try to remove .suo file which is storing some enviroment/solution settings. This helped me.
Just had this problem with VS 2019.
I tried disabling / enabling codelens and it didn't work.
I deleted the .suo after that and it didn't work.
I tried disabling / enabling codelens again (after deleting the .suo) and now it works again.
UPDATE (about 2 weeks later):
It started happening again and this time I disabled IntelliCode in Extensions and all of a sudden Codelens started working again.
UPDATE AGAIN (25 Nov 2019):
I reported this to Microsoft and had a dialog with them. You do not have to turn off all of Intellicode at this time, only disable Intellicode Refactorings in Tools -> Options -> Intellicode. The actual fix is slated for VS 2019 16.4 I believe.
You may have circular references in your solution that prevents CodeLens from working. Some details were provided in the comments for this issue on the Visual Studio Connect site:
Somehow, two of my projects in my solution ended up referencing each
other causing a circular reference. I think it was a by-product of
Resharper's shortcut to reference an undefined class. Once I was
cleaned up all of the references, I'm now getting valid values in my
reference counts.
How did you go about "cleaning" up references?
In my case, my solution has multiple project files. In the references
folder of Project A, there was a reference to Project B. In the
references folder of Project B, there was a reference to Project A.
This was causing the circular reference. If you try to do this
"manually", VS will prompt you with a warning regarding the circular
reference.
To clean this up, I removed the reference to Project B from my Project
A. I had do some minor class definitions in my Project B so everything
would still compile in the end.
I found out that if you block the Visual Studio with the Firewall, the Code Lens did not work.
So unblock it from the firewall to make it work.
Or edit Firewall settings for file:
C:\Windows\Microsoft.NET\assembly\GAC_32\
Microsoft.Alm.Shared.Remoting.RemoteContainer\
v4.0_12.0.0.0__b03f5f7f11d50a3a\
Microsoft.Alm.Shared.Remoting.RemoteContainer.dll
I had this problem with VS2015 that already had "update 1" installed.
The thing was that I originally installed VS2015 with the "custom" setup, not the "default" option, and I accidentally left out the "Git for Windows (3rd party)" option under "Common Tools".
This can be fixed by these steps:
Run the VS2015 setup again (from control panel - uninstall program)
Right click VS2015, select "Change"
On popup screen, select "Modify"
On setup screen, select "Git for Windows (3rd party)"
Move on with the setup, install selected features
In Visual Studio Professional or Enterprise you can enable CodeLens by doing this:
Tools → Options → Text Editor → All Languages → CodeLens->Enable
This is not available in some Community Edition versions
Try deleting .suo file inside of the hidden .vs folder in your project. This worked for me in VS 2017.
My Problem
Always directly after enabling CodeLens, press OK, i see the extra space required for the CodeLens information and than it disappears and when i look at the options again it is diabled. Driving me nuts.
Approaches
Deleting caches/configurations. Clean start without Extensions work. Normal start without ReSharper works. Reinstall ReSharper + deleting cahces -> False behavior
Solution
Unter Extensions - ReSharper - Options - Environment - Performance Guide was "Disable CodeLens for all languages" set to "Fix Silently". Set to Ignore -> WORKS!
hope this helps someone
I had the same problem, but one's of my colleagues who has the same development environment than me, doesn't have it...
The only one difference between our both environment was the quantity of RAM. There is 10GB allocated to his VM, and on mine, there is 6GB allocated. Since I upgraded the quantity of RAM allocated to my VM to 8GB, all my references are shown !
Installing Update 1 for Visual Studio 2015 fixed the problem for me.
Download Update 1
After reading the answer to this Stack Overflow question CodeLens only showing references? I decided my problem with Codelens was I was running Visual Studio 2015 Update 1 but was using Team Foundation Server 2012. I upgraded to TFS 2015, which upgraded in place and didn't require any new settings or URIs to be connected to Visual Studio as before. Then I reloaded my solution - but I still had the issue where it just said "– references" everywhere. I closed Visual Studio, started it again and reloaded my solution and finally I saw the correct reference counts as they used to show.
I found on the new VS 2015 update 3 it happens on a large class in a medium level solution 10+ projects and has nothing to do with circular references, a bad SUO file, or other things. It appears just deleting the temp file location(as mentioned already), closing VS and then reopening and hitting 'ALT+2'(forcing a reference find for Code Lens) made it magically work for me.
It also appears in some solutions and projects Visual Studio will create an old referenced suo file in .vs folder. I don't know the exact rhyme or reason, but it could be created in my case and the CodeLens worked again. It could potentially be a Visual Studio options is somehow referenced in projects under source control. As I know this happened with an older solution I have upgraded many times that was under GitHub control and it does have an .gitignore file(ignore files could change depending on source control). Suffice to say I have had similar things happen with other techs in the past when there is a lock on a source control file that should be updated and won't update. Simple answer is to add to an ignore and delete the settings file.
I have Visual Studio 2017 Professional on Windows 10.
I have observed this under several circumstances:
MicroSoft decided I needed some critical update for Windows and it installed while I was working - causing some of the VS components to crash.
Visual Studio update was received in background.
Some component of Visual Studio crashed - not the VS just some attached feature (did not note exactly which one)
No known cause.
In each of these cases I did in order (sometimes it worked after each of these)
Build / Rebuild solution
Build / Clean Solution
Close and Restart Visual Studio
Remove Symbols cache, restart VS
Close BOTH VS and SSMS and restart them
Close VS and Restart Windows
Close VS, force all pending Windows updates to load, restart Windows
In options, Uncheck Codelens/apply and re-check/apply (OK button)
I tried most of the solutions above without luck, as I also saw this problem. On top, certain newly added classes were showing up as white/black (regular text) in Visual Studio.
Changing to Release typically helped, but wasn't a long-term solution.
However, this helped on both issues - verified on another machine. Maybe some of the steps can be left out.
Close all document tabs
Clean solution
Right click on solution, click "Enable Lightweight Solution Load"
Close solution
Reopen solution
Right click on solution, click "Disable Lightweight Solution Load"
Close solution
Reopen solution
Rebuild
Explicitly enable CodeLens in the workspace settings.json:
// show code lens on editor
"editor.codeLens": true,
Verify that the following properties show on the editor:
// inline count of reference for classes, interfaces, methods, properties,
// and exported objects
"typescript.referencesCodeLens.enabled": true
I could fix my problem with C# CodeLens and Omnisharp.
My C# extension was 1.25.0.
What I did to fix my problem:
C# extension -> Unistall -> Install another version -> Version 1.24.4
After that in the settings I searched for "omnisharp: use global mono" and set it from "auto" to "alwayse".
Then restart Omnisharp and wait for it to compile and show references.
Removing data from %temp% folder resolved my issue in VS 2022.

Visual Studio - Error when clicking on Solution -> Properties (Object reference not set to an instance of an object)

When i try to access my solution Properties, i get the following error:
Object reference not set to an instance of an object
I am using VS 2012. What could be the cause of this?
Some extensions may cause this.
Try disabling extensions and restarting Visual Studio.
Quite often error will be gone even if you re-enable extensions after this.
There's a bug report on Microsoft Connect (link).
It is marked there as "Closed as External", but it seems that it may occur randomly with any extension, so would be worth voting it there to bring it to Microsofts attention.
In my case, the problem was solution-specific. NuGet was causing this error, but not the extension itself but a NuGet package that generated an error on VS load. When I opened NuGet Package Manager Console I saw a big red text with a description of the error. In my case it was T4Scaffolding.Core package, which in turn is a dependency of MVCMailer.
If this is your case, you will probably see what package generates an error in PM Console.
I faced this dialog too and i'm not sure what exactly causes this as i couldn't even open the NuGet console to see detailed error messages.
Closing Visual Studio, deleting %AppData%\Microsoft\VisualStudio and restarting Visual Studio worked for me as it causes a reset of various things like window configurations.
I think if this dialog is displayed some files may be corrupt in %AppData%\Microsoft\VisualStudio and by deleting that folder Visual Studio can start normally again.
Update:
The issue arises on my machine when i start Visual Studio by using "run as administator" whereas Visual Studio has been started before without that option and %AppData%\Microsoft\VisualStudio had been created without the administator association.
Visual Studio 2013: I had this issue when I tried opening TOOLS -> Extensions and Updates.
I used #ViRuSTriNiTy idea, but only cleaned the files from:
C:\Users[myUserName]\AppData\Local\Microsoft\VisualStudio\12.0\Extensions
There are 2 cache files over there.
Deleted them and restarted VS2013 and it was fixed
The way it was happening for me might be unique to me/my setup, but I'd love to know if anyone else has this happen, and if they find out why:
If I launch an .sln file by double-clicking it, it will load VS and I can right-click the Solution and get Properties to come up no problem.
If I go to "Open Project" on the Visual Studio welcome page or from File > Open > Project/Solution, navigate to the .sln file and launch it by selecting it and clicking "Open" in the File dialog, that's when I have this issue.
I'm going to just always launch the .sln file from now on, but I'd love to know why this happens when using "Open Project" from the welcome page or from File > Open > Project/Solution! I tried going into Tools > NuGet Package Manager > General and I unchecked the options for allowing NuGet to download missing packages and Skip applying binding redirects, and under Package Sources I de-selected the checkboxes (my dev machine does not connect to the internet). Environment > Extensions and Updates: I tried it with and without "Load per user extensions when running as administrator" and running it as an Admin and without running as Admin. Also tried just deleting everything at C:\Users\me\AppData\Local\Microsoft\VisualStudio. No change from those 2 bullets above.

Visual Studio 2010 creates folder in current working directory on launch

Every time I launch Visual Studio 2010, it creates a directory called "Visual Studio 2010" in the current working directory at the time I launched it. It just started doing this at the same time that it forgot all of my toolbar settings and so on.
I've clearly got an incorrect setting somewhere, but I can't find it.
Under Tools\Options\Projects and Solutions\General I have:
Projects location:
D:\ian
User project templates location:
M:\Visual Studio 2010\Templates\ProjectTemplates
User item templates location:
M:\Visual Studio 2010\Templates\ItemTemplates
How do I stop this spurious .\Visual Studio 2010 directory being created and tell it to use the proper one on M:\ instead?
Edit: Since I've started a bounty on this, please be reasonable and don't post a suggestion that doesn't answer the question. For example, don't say 'Have you tried reinstalling?' or 'Have you tried deleting all your settings?' Thank you for your understanding.
Damn, too annoying. You don't know which plugin/addon or something do this...
So we can't find it too* Ok. thanks god, stackoverflow is here... Here is the solution;
Press Win + R
Type "regedit"
Go to this folder by treeview; "[HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\10.0]"
Edit everything which are like this; "Documents\Visual Studio 2010\"
Last step; In registry editor, press Ctrl + F
Search the string "Documents\Visual Studio 2010\". And change them too if anything appears...
I suggest an advanced registry editor for this.
Good luck & best regards...
UPDATE:
And if you still have the problem; open VS2010, go to "tools" > click "extension manager" > try to disable all plugins(I mean all of them). And play with VS again, create a new project etc. If there will be created a new folder( named like "Visual Studio 2010" ) in the "documents" then we will sure this comes from the ide:visual studio 2010( not add-ons ). Also, if you are using a "subversion control software" or "sdk service" try to disable them too... ( with disabling services in OS management )
This is the final answer that worked for me.
It turns out that Visual Studio 2010 regularly and automatically exports your settings file. (You would probably expect it to save your settings on exit, but not export them unless you explicitly ask it to.) I think it does this every time you quit, but it seems to create the directory into which it will export as soon as it is launched. This is the problem I was seeing.
This is how I resolved it:
Tools > Options > Environment > Import and Export Settings
The field Automatically save my settings to this file: was just Visual Studio 2010\Current Settings.vssettings. This is a relative path, so the folder Visual Studio 2010 was being created in the current working directory. I changed it to an absolute path M:\Visual Studio 2010\Current Settings.vssettings and this solved the problem.
This is another different way, so I'm adding a new answer here.
I don't want to edit my previous answer too much( It's started to looks ugly )...
Just go that link, download/copy the script, carefully save and edit for your needs;
https://github.com/jerker-back/VSUtilities/blob/master/custom_vspaths.js
and run it under admin.user.rights( or disable windows uac )...
Is it possible that you have a macro in your EnvirommentEvents that is causing this? Go to menu Tools -> Macros -> Macros IDE. Look in each of the macros trees in the Project Explorer for EnvironmentEvents to see if any of those macros is the culprit.
None of the solutions here worked for me. I don't think we've seen the golden bullet yet.
I had been writing to the same settings folder for years and all of a sudden that was no good for visual studio anymore. The folder was a networked folder. One day, every time I fired up a solution it would start making me yet another Visual Studio 2010 folder in the same directory as the .sln file.
I tried (and re-tried) specifying where settings are saved. I also went through and did some registry changes. In the end, what seemed to fix it was to re-config the IDE to use a local path, and then re-config it again to use the network path. I did this for all the paths you can set in Tools...Options...Environment...Import and Export Settings as well as Tools...Options...Environment...Projects and Solutions...General. And now I'm back to the setup I've been using for the last few years. It has stopped creating new folders every time I open a solution. For now, anyway.
The brute-force solution:
Run regedit and rename the folder [HKEY_CURRENT_USER\Software\Microsoft\VisualStudio] to something like "VisualStudio_BAK".
Run devenc.exe /resetsettings to reset all settings to default.
If you don't know what you are doing, don't try this...! ;-)

How do I REALLY reset the Visual Studio window layout?

I had a plugin installed in Visual Studio 2008, and it created some extra dockable windows. I have uninstalled it, and I can't get rid of the windows it created - I close them, but they always come back. They're just empty windows now, since the plugin is no longer present, but nothing I've tried gets rid of them. I've tried:
Window -> Reset Window Layout
Deleting the .suo files in my project directories
Deleting the Visual Studio 9.0 folder in my Application Settings directory
Any ideas?
Have you tried this? In Visual Studio go to Tools > Import and Export Settings > Reset all settings
Be sure you back up your settings before you do this. I made the mistake of trying this to fix an issue and didn't realize it would undo all my appearance settings and toolbars as well. Took a lot of time to get back to the way I like things.
Try devenv.exe /resetuserdata. I think it's more aggressive than the Tools > Import and Export options suggested.
Also check Tools > Add In Manager and make sure there aren't any orphans there.
How about running the following from command line,
Devenv.exe /ResetSettings
You could also save those settings in to a file, like so,
Devenv.exe /ResetSettings "C:\My Files\MySettings.vssettings"
The /ResetSettings switch, Restores Visual Studio default settings. Optionally resets the settings to the specified .vssettings file.
MSDN link
I had similar problem except that it happened without installing any plugin. I begin to get this dialog about source control every time I open the project + tons of windows popping up and floating which I had to close one by one.
Windows -> Rest Windows Layout, fixed it for me without any problems. It does bring the default setting which I don't mind at all :)
If you want to reset the window layout. Then
go to "WINDOW" -> "RESET WINDOW LAYOUT"
If you have an old backup copy of CurrentSettings.vssettings, you can try restoring it.
I had a completely corrupted Visual Studio layout. When I tried to enter debug, I was told that VS had become unstable. When I restarted, my window layout would then be totally screwed. I tried restoring the VS current user settings in the registry from a backup, but that didn't help. However, restoring CurrentSettings.vssettings seems to have cured it.
There seems to be a bunch of binary stuff in there and I can imagine it gets irretrievably corrupted sometimes.
Note: if you have vs2010 and vs2008 and you want to reset the 2008, you will need to specify in command line the whole path. like this:
"C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\devenv.exe" /resetsettings
If you don't specify the path (like devenv.exe /resetsettings), it will reset the latest version of Visual studio installed on your computer.
I close them, but they always come back
When you say "they always come back" do you mean "next time you restart Visual Studio" or "immediately"?
One quirk of Visual Studio (at least VS2005) is that settings aren't saved until you exit. That means that if VS crashes at all while you are using it, any layout changes you made will be lost. The way around this is to always gracefully exit when you have set up everything like you want it to be.
Not sure if this will help your particular situation though.
I tried most of the suggestions, and none of them worked. I didn't get a chance to try /resetuserdata. Finally I reinstalled the plugin and uninstalled it again, and the windows went away.
If you've ever backed up your settings (Tools -> Import and Export Settings), you can restore the settings file to get back to a prior state. This is the only thing that I've found to work.
If you want to reset your development environment of your visual studio, then you can use Import and Export setting wizard. see this for all steps:
http://www.authorcode.com/forums/topic/how-to-reset-development-environment-settings-of-your-visual-studio/
Window -> Reset Window Layout didn't exist for me. For anybody looking in 2022 or later, I finally found the answer! The crucial information, buried in a VSCode update release note, was right at the bottom of this section. Here it is if the link breaks in the future:
If you'd like to reset all views back to the default layout, you can run Views: Reset View Locations from the Command Palette.

Resources