skip to Main Content

If I type the following code into Visual Studio 2022 Professional Edition:

public string foo = string.Empty;

Visual Studio will automatically modify this to String.Empty and then issue this warning:

IDE0049 Name can be simplified.

Activating the "potential fixes" will suggest changing the code back to string.Empty – as I had originally entered.

Is there any way to prevent this without losing other significant functionality that Intellisense autocomplete provides?

EDIT: I’ve come to realize this issue is intermittent. On the same project, it will sometimes occur and sometimes not. When the problem occurs, the autocomplete options for the phrase I am typing show "string" and "String" as the first and second options, respectively, but for some reason the SECOND option ("String") is highlighted as the default choice. If I press the "." on the keyboard at this time, it chooses "String" as it was the selected option. Perhaps this has to do with the way the autocomplete options are populated as I notice the options are sometimes populated at different times and the list then resorts itself based on the newly discovered options.

EDIT: After playing around with this for another 5-10 minutes, the AI code assistant learned to auto-suggest "string.Empty to accept" which seems to supercede the autocomplete and this issue can not be reproduced on my system at this time.

2

Answers


  1. Chosen as BEST ANSWER

    Although the problem persisted after resetting visual studio per the steps outlined in this answer, after repeatedly reproducing the issue, the AI code assistant learned to auto-suggest "string.Empty (tab) to accept" which seems to supercede the autocomplete and the problem stopped occuring.


  2. I tested this:

    using System;
    
    namespace WSL_Testing
    {
        internal class Program
        {
            static void Main(string[] args)
            {
                Console.WriteLine("Hello World!");
            }
        }
        public class Person : Object {
            public string foo = String.Empty;
        }
    }
    

    I notice the information:

    enter image description here

    But I didn’t notice the Visual Studio have an operation that "correct" the spell.

    I think this strange operation should comes from sync settings(VS2022 professional needs login in, I think something changed on your side compare to the original settings.).

    So please follow the below steps:

    1, Make sure not effected by the settings of the async user’s settings, please turn off the user settings async:

    enter image description here7

    enter image description here

    2, Reset the language environment collection settings:

    enter image description here

    enter image description here

    enter image description here

    enter image description here

    If you still encounter the issue after above steps, please share share a minimal code example that can reproduce the problem, because the statement may behave differently depending on where it is written.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search