VS Designer replaces "empty" strings with resource identifier pointing to empty strings - c#

Weird problem, started with migration to Visual Studio 2010.
Some forms, when opened, will have some objects' properties set to a string that is empty in resource file. Most often these are control properties like ImageKey, ToolTipText and for UltraGrid some columns get columnX.Header.Caption set to that string. This will obviously remove set images and give wrong column header texts in other locales. Additionally tooltips will show up in weird places (like tab panel body).
This string (strSaveInterestDetails8 below) is empty in Strings.resx (<value />), but not empty in Strings.fi.resx. When I changed this string to have a space, designer started to use an other "empty" string from Strings.resx..
These forms are all derived from common base, but it does not have anything special/suspicious. Debugging these from additional devenv instance failed, since the debugger never broke on the set breakpoints (thrown exceptions in internal VS code were caught).
example:
ultraGridColumn23.Header.Caption = global::Company.Module.Properties.Strings.strSaveInterestDetails8;
...
this._timespanCheck.ImageKey = global::Company.Module.Properties.Strings.strSaveInterestDetails8;
...
this.tabPage1.ImageKey = global::Company.Module.Properties.Strings.strSaveInterestDetails8;
this.tabPage1.ToolTipText = global::Company.Module.Properties.Strings.strSaveInterestDetails8;
So has anyone run into something similar or has better google-fu?

This is a long standing bug in Visual Studio. Microsoft is aware of the issue, but still no fix. You can vote up the issue here:
https://connect.microsoft.com/VisualStudio/feedback/details/683661/windows-forms-designer-cs-files-corrupt-after-changing-language#tabs

I'm having the same problem, but with VS2008. However, a VS2010 Web Developer Express version is also installed on my system (since a couple of months). First, I was developing in a project that uses multiple language resources and then I opened up another VS solution to change something on a form. The Windows Form Designer replaced all the empty strings in the Designer.vb file with a string resource identifier from the first project!
I could solve the problem by closing Visual Studio and reopen the solution.

In our experience, this is usually a bug caused by the presence of the text string
<value />
in the xml of a resx file. When you edit and save the form designer, all the empty strings "" in the designer file get mapped to the key associated with this self-terminating node.
Theses spurious <value /> entries sometimes appear if you start building a project while the resource editor has still got the flashing cursor in the 'new row' line, and there is no text associated with the key.
Search the project for <value /> and eliminate them from the resx files. Then clean and rebuild the project, (which will fail), then fix the compile errors by replacing them with ""
Hope this helps.

I think this will work for you. Check the accepted solution.
Or maybe this.

Related

Visual Studio 2019 closing curly brace not under the opening brace (it's fully left aligned instead)

Recently the closing curly brace start to align on the fully left instead of under the opening brace, but only when the braces are empties :
(I'm in Visual Studio 2019, in C# code)
Steps :
write this :
namespace myNameSpace
{
class myClass
{ }
}
Then hit return while in between the class braces, it did this :
namespace myNameSpace
{
class myClass
{
}
}
Note the class closing brace not being under the opening one.
How can I have this instead, where is the formatting option ?
namespace myNameSpace
{
class myClass
{
}
}
Thanks,
Indentation and bracing styles tend to be religious issues. When you move from team to team, you end up having to learn the local brace/indent style. There's a whole Wikipedia article on it (https://en.wikipedia.org/wiki/Indentation_style).
In Visual Studio, you can setup your preferred brace/indent style. My guess is that your bracing/indentation is busted and needs to be reset.
To get there:
Tools ->> Options ->> Text Editor ->> C# ->> Code Style ->> Formatting ->> Indentation
Once you are there, if thing are the way you want them, change them to something else before OK-ing out of the dialog. Then do it again and change it back. If they don't match your desired style, just change things (the idea being - you need to make a change so that your change gets saved).
Good luck
I've seen this happen before in various versions of VS. It's not really reproducible, but sometimes for no explainable reason, VS just starts acting this way.
There are a couple of ways to handle this. The quick fix is to just hit
ctrl+k+d
And that will auto-align all of the code (and comments) on the open file. While that will fix the misaligned brackets after the fact, it won't stop VS from still doing it.
If it gets too annoying (which it can!) then what you can do is a ctrl+a to copy everything. Then paste it into a text file (so you don't accidentally lose it). Remove the file from the project. Then, delete the actual file from the working folder. Close and re-open VS. Then re-create the file and paste all of the contents back into it.
That should solve the problem.
Ok, it’s appeared, but I might be wrong, that the smart tab management had changed lately and that now it is no longer inserting tab at the beggining of a second empty line in a bloc (like some other code editor). Therefor leaving only a space on the second line, leading to my “problem”.
I always used smart tab indenting for all languagse and then lately it seen to have changed then causing this. So the solution for me was to go back to Block Indenting and it work well. I don’t know what other differences that may cause, but...
NOTE: That this only occur if using the Keep tabs option
Thanks all, your comments lead me to a solution (or at least a work-around).
Auto-formatting as you type looks to be turned off by default in Visual Studio 2019. To auto-format your code, go to Tools -> Options -> Text Editor -> C# -> Code Style -> Formatting and select the option Automatically format when typing then select your preferences as to when auto-format should be triggered. Example screenshot:
Auto-format option in Visual Studio 2019

Conflict : 'space Bar' changes to 'tab' when something is edited

I am getting this conflict every now and then, the spaces(....) are shown as a tab(->) when I am changing something in code. I am attaching an image, where I compared my file with the previous one. If anyone encountered with same error please let me know.
Conflict Image:
You can either change to an external comparer, one that can be configured or setup the code formatting in visual studio to adhere to the project formating guidelines whatever they are.
To configure the Visual Studio, just go Tools --> Options --> Text editor --> All languages (or the one you are using) --> Tabs and change the settings to whatever behaviour works for you.
You seem to have the editor tool configured the use tabs instead of spaces.
How you can control this in VS is answered by https://stackoverflow.com/a/51922994/3906760.
There is, however, another way how this could be controled from "the outside". There is editorconfig (you can spot this, if there is an .editorconfig file your repository), then on save the files will be converted automatically. This is also a way, to consistently push the coding rules to other developers.

Visual Studio keeps changing references to resources

I have a strange problem with Visual Studio. I have a large application in C# with lots of forms and also a .resx file that contains strings. I have various language versions of the .resx file, e.g.
MyApplication.resx,
MyApplication.ja.resx
Now take this piece of code, which refers to a windows control (a label) is contained within the control definition part of the code:
this.uxMyLabel.BackColor = System.Drawing.SystemColors.Window;
resources.ApplyResources(this.uxMyLabel, "uxMyLabel");
this.uxMyLabel.Name = "uxMyLabel";
this.uxMyLabel.ReadOnly = true;
this.uxMyLabel.Text = global::MyNamespace.MyApplication.MY_TEXT_STRING;
Every now and again I will build my application only to find that that last line has changed to
this.uxMyLabel.Text = global::MyNamespace.MyApplication_ja.MY_TEXT_STRING;
Since there is no file called MyApplication_ja.resx then of course the build fails and I have to edit and change it back to MyApplication
I am not sure when this change happens (while I'm editing the code? While I'm building it?) but it only happens occasionally and to lots of different controls, often a whole file at a time. (though never to the entire project)
I am editing the file in question elsewhere, though not anything to do with that particular control.
Why does this happen?
I'm not fully aware about the configurations at your end, therefor I'm feeling a little constraint in analyzing why VS is having an affinity for Japanese("ja") localisation assembly.
But I do see an issue with the way your Form/UserControl is localized, so I'll point it out. And I think sticking to the correct pattern may help getting rid of the mentioned behavior.
The controls should not pick values from global resource like this.uxMyLabel.Text = global::MyNamespace.MyApplication.MY_TEXT_STRING;
instead Localizable property of the Form/UserControl must be set to true.
This will create a .resx file exclusively for the Form/Usercontrol and will take out all culture specific properties (of all controls) from the designer to the resx .
This will enable the developer (or designer) to set localised texts for different languages at design time. here is a link - https://msdn.microsoft.com/en-us/library/y99d1cd3(v=vs.100).aspx#
Understanding that you are working on massive application with many forms, my suggestion may be a bit too time consuming nbecause it will involve localizing each control again for all language.
But incase the problem you mentioned become a pain, perhaps you can give it a try on the most notorious forms(user controls) first.
Hope it helps.

Observing a question mark sign (?) on every file of a c# project after i reload the project [duplicate]

I often get blue question marks on files in my VS2012 Solution Explorer when opening a solution bound to Perforce through P4VS.
Looks like something is having trouble to "synchronize" with the depot/workspace/whatnot. Hitting "Refresh View" always solves the issue but I'm growing tired on doing this everyday:
This is my VS version:
Microsoft Visual Studio Professional 2012
Version 11.0.61030.00 Update 4
And P4VS:
2014.1.85.4506
This is persistent across P4VS versions for a few months now, and seems to be affecting sometimes individual files, sometimes entire projects, with no apparent pattern.
How can I diagnose what's going wrong, be it a server issue, a VS issue, a workspace issue?... The Perforce Source Control output shows nothing special.
Actually it's not entire folders, it's entire projects. It appears that even if refreshing a project "fixes" the issue for one run, re-opening the solution brings it back. Whereas I think that for individual files, refreshing them solves the issue once and for all. I'll play with it a bit more to confirm that.
To help diagnose what is going wrong you should probably turn on logging, and check the preferences that will show everything in the output window. For the P4VS log, go to:
Tools- > Options -> Source Control -> Perforce - Logging
(This is not the same thing as the Visual Studio Activity log.)
There could be a possibility that you are getting disconnected and refresh reconnects you. I am not sure if you have your connection set to use solution-specific settings, since you did not mention the connection dialog coming up.
This "solved" the issue for me, at least for the entire projects that went blue-question-marked:
1) Tools > Options
2) Source Control
3) Perforce - General
4) Tick the option "Treat Solution/Project as directory when
selected"
Not sure why but that's one less annoyance for me every day. Thanks to Perforce support for suggesting that.
The file is probably not marked for version control. I noticed this icon in one file and opened Perforce to check. For whatever reason, this file was not marked for add in Perforce. After marking the file for add and submitting, the blue question mark went away.

How to see full document generated by xml-comments

I have writen a method such as:
/// <summary>
/// A method having xml-comments
/// This comment could be very long
/// </summary>
/// <param name="input">Input parameter</param>
/// <returns>Calculated value</returns>
int CommmentedMethod(int input) {
return Calc(input);
}
But when I use this method, Visual Studio (I'm using VS 2010) just show up "A method having xml-comments This comment could be..." not a full document.
Is there an option to show it?
Updated picture:
Thanks :-)
You can use Ctrl + Shift + Space key combination to view the parameter information.
In the following screenshot you can see the overloads, definition and parameter information being shown after clicing Ctrl + Shift + Space with the caret on Format method.
This works in VS2010 as suggested by an answer above. It works in VS2010 showing the entire string fully in tooltip. I suggest you retry in a fresh project again and rebuild the project and see. Intellisense normally uses the text for tooltip that it has used recently. So if you have not completed it on the first time and built it, its not going to show fully. Rebuiding the project should work though. Having said this, I just tried your code and it worked like a dream. So, Please try in a fresh project and see.
Use Quick Info (the tooltip that's shown when you hover your mouse over a method). This will display more than one parameter per line and therefore be able to display more parameters without truncating.
Set a smaller font or font size for tooltips. This can be changed by going to Tools->Options->Environment->Fonts and Colors, choosing "Editor Tooltip" in the dropdown at the top, and setting a different font and/or size.
P.S: However there is one problem if you have done so. Did you migrate from other version of Visual Studio and transfer settings. Because Visual studio has capabilities to import and export settings which you can include intellisense settings also. It may be something I'm not aware of, if you have done so.
Please install SP1 for VS2010 because that's what is solving the problem of truncating quickinfo else reduce font size as I have mentioned ! Hope this helps ! This works by all means and verified !!
If you use ReSharper you can press CTRL+SHIFT+F1. I don't think Microsoft has this feature.
The tooltip for VS2010 will show the entire contents. I just tested with a new install of VS2010 with no installed addins (Windows 7 pro).
You might try clearing the Automatically adjust visual experience based on client performance flag in the Options... dialog General section and then checking Enable rich client visual experience. The documentation on exactly what this provides is vague, but I suspect this could affect the tooltip display.

Categories

Resources