I suggest you ...

Get rid of IDE0017 C# Object initialization can be simplified

I recently switched to VS 2017 RC as my primary development mode because I read it was production ready.

Now every class I compile you try and show me a warning, 'Object Initialization Can Be Simplified'.

Get rid of this warning, or at the very least make it something that has to be turned on, do not turn it on by default.

You can't just introduce something that breaks 12 years worth of C# code in our code libraries.

41 votes
Vote
Sign in
(thinking…)
Password icon
Signed in as (Sign out)
You have left! (?) (thinking…)
Lou shared this idea  ·   ·  Flag idea as inappropriate…  ·  Admin →

10 comments

Sign in
(thinking…)
Password icon
Signed in as (Sign out)
Submitting...
  • Patrick Nelson commented  ·   ·  Flag as inappropriate

    Please don't add StyleCop-like rules that are on by default and clutter up code in the editor - especially if it's not possible to turn the rule off for a whole project. Keep in mind older code bases written before "var" have this warning everywhere.

  • haken commented  ·   ·  Flag as inappropriate

    To disable this suggestion, add

    dotnet_style_object_initializer = false:none

    to your .editorconfig file.

  • Mike Jiang commented  ·   ·  Flag as inappropriate

    Or just like this writing code to solve it(add braces)
    Money cash2 = new Money();
    {
    cash2.Amount = 40M;
    }

  • Mike Jiang commented  ·   ·  Flag as inappropriate

    Add pragma as below,but everywhere giving this message have to be done.
    #pragma warning disable IDE0017
    Money cash2 = new Money();
    #pragma warning restore IDE0017

  • Anonymous commented  ·   ·  Flag as inappropriate

    this command generates the info message:
    FileWriteLog = New StreamWriter(LblFileName.Text, False)
    to get rid of you can use the following two solutions:
    method 1: "enable/disable message info"
    #Disable Warning IDE0017 ' Simplify object initialization
    FileWriteLog = New StreamWriter(LblFileName.Text, False)
    #Enable Warning IDE0017 ' Simplify object initialization
    method 2: use "witdh"
    FileWriteLog = New StreamWriter(LblFileName.Text, False) With {
    . AutoFlush = True
    }

  • Chris commented  ·   ·  Flag as inappropriate

    I am using Microsoft Virtual Academy "visual Basic Fundamentals" with Bob Tabor. I am using it as of 6/20/2017 and is does break the code. It will not run through even though it says "Object initialization can be simplified" I am following the Instructor character by character and it fails in lesson 15 "Understanding Classes" So upgrade the lesson or enable the suggestion to be turned off.
    Thanks

  • S Olson commented  ·   ·  Flag as inappropriate

    A major downside to following the 'Object Initialization Can Be Simplified' advice is that it makes it much harder to debug and issue happening inside the initialization.

    At the very least add a way disable the setting for the whole solution and check it in so that all developers get it by default. Currently to suppress it you have to add it for every single place. Perhaps it could be supported by the .editorcofig file?

  • Anonymous commented  ·   ·  Flag as inappropriate

    It is not a warning it is a message - not sure why you think it breaks your code !
    However, I do agree that these new 'messages' are extremely annoying and would be good if they could be globally turned off.

Feedback and Knowledge Base