Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. The Lounge
  3. .NET and the nullable configuration

.NET and the nullable configuration

Scheduled Pinned Locked Moved The Lounge
csharpcomhelpquestionworkspace
29 Posts 18 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Marc Clifton

    Does anyone actually use .NET 7 with enable? I find this option makes life such a PITA that I always go into the .csproj file and disable it. The warnings are non-stop:

    Non-nullable property 'foo' must contain a non-null value when exiting constructor. Consider declaring the property as nullable

    Converting null literal or possible null value to non-nullable type.

    Dereference of a possibly null reference.

    Possible null reference assignment.

    Nullable value type may be null.

    And that's just a partial list, I believe. And that last one, "Nullable value type may be null" is the most amusing one. Seriously, if you have the "Nullable" option enabled, do you actually fix all those warning?

    Latest Articles:
    SVG Grids: Squares, Triangles, Hexagons with scrolling, sprites and simple animation examples
    An SVG Analog Clock

    J Offline
    J Offline
    jschell
    wrote on last edited by
    #9

    Some people seem to find some computer idioms and technologies difficult to understand. And then they then attempt to popularize that poor understanding as being a failure in the idiom/technology rather than leaving it where the problem actually belongs. Myself I like null. Easier than coming up with a long list of magic values that represent the same thing as 'no value'.

    L 1 Reply Last reply
    0
    • M Marc Clifton

      Does anyone actually use .NET 7 with enable? I find this option makes life such a PITA that I always go into the .csproj file and disable it. The warnings are non-stop:

      Non-nullable property 'foo' must contain a non-null value when exiting constructor. Consider declaring the property as nullable

      Converting null literal or possible null value to non-nullable type.

      Dereference of a possibly null reference.

      Possible null reference assignment.

      Nullable value type may be null.

      And that's just a partial list, I believe. And that last one, "Nullable value type may be null" is the most amusing one. Seriously, if you have the "Nullable" option enabled, do you actually fix all those warning?

      Latest Articles:
      SVG Grids: Squares, Triangles, Hexagons with scrolling, sprites and simple animation examples
      An SVG Analog Clock

      T Offline
      T Offline
      TNCaver
      wrote on last edited by
      #10

      That annoying nonsense started with .NET 6. I'm trying to be a good and obedient Microsoftie, leave Nullable enabled and deal with it in the code like they suggest. So I use truck loads of ! signs when I know good and well that it will not be null whether or not VS can see that I am checking for null values before referring to the object. The most annoying place it warns me of possible nulls is for string properties in a POCO. Seriously, MS, most of the time it doesn't make any difference whether or not those strings are null or not and warning me that they may be is useless and generates a false warning.

      There are no solutions, only trade-offs.
         - Thomas Sowell

      A day can really slip by when you're deliberately avoiding what you're supposed to do.
         - Calvin (Bill Watterson, Calvin & Hobbes)

      1 Reply Last reply
      0
      • D dandy72

        I found it rather jarring the very first time I built a .NET project using .NET 7 (something that had actually started life as a .NET Framework 4.8 project), so there were quite a few "fixes" to implement. But I came around rather quickly, and now kinda wished older versions were that restrictive/explicit.

        M Offline
        M Offline
        Marc Clifton
        wrote on last edited by
        #11

        You and others are convincing me that I should just bite the bullet and fix the code. ;)

        Latest Articles:
        A Lightweight Thread Safe In-Memory Keyed Generic Cache Collection Service A Dynamic Where Implementation for Entity Framework

        D P 2 Replies Last reply
        0
        • M Marc Clifton

          Does anyone actually use .NET 7 with enable? I find this option makes life such a PITA that I always go into the .csproj file and disable it. The warnings are non-stop:

          Non-nullable property 'foo' must contain a non-null value when exiting constructor. Consider declaring the property as nullable

          Converting null literal or possible null value to non-nullable type.

          Dereference of a possibly null reference.

          Possible null reference assignment.

          Nullable value type may be null.

          And that's just a partial list, I believe. And that last one, "Nullable value type may be null" is the most amusing one. Seriously, if you have the "Nullable" option enabled, do you actually fix all those warning?

          Latest Articles:
          SVG Grids: Squares, Triangles, Hexagons with scrolling, sprites and simple animation examples
          An SVG Analog Clock

          C Offline
          C Offline
          Chris Maunder
          wrote on last edited by
          #12

          We do, and at first I hated it, but now I've embraced it. We find it cuts down on lots of null-ref opportunities. Sure, it can be annoying sometimes, but the occasional "!" on the end of a var, combined with the much nicer "if x is not null" makes the code very clear. Assuming you know what a trailing ! is...

          cheers Chris Maunder

          M 1 Reply Last reply
          0
          • J jschell

            Some people seem to find some computer idioms and technologies difficult to understand. And then they then attempt to popularize that poor understanding as being a failure in the idiom/technology rather than leaving it where the problem actually belongs. Myself I like null. Easier than coming up with a long list of magic values that represent the same thing as 'no value'.

            L Offline
            L Offline
            lmoelleb
            wrote on last edited by
            #13

            No one is suggesting you should not use null. The nullable check makes it explicit where you intend to use it - just as it already is for value types.

            J 1 Reply Last reply
            0
            • M Marc Clifton

              You and others are convincing me that I should just bite the bullet and fix the code. ;)

              Latest Articles:
              A Lightweight Thread Safe In-Memory Keyed Generic Cache Collection Service A Dynamic Where Implementation for Entity Framework

              D Offline
              D Offline
              dandy72
              wrote on last edited by
              #14

              My first reaction was, "ugh, did they really do that?" followed by "am I really gonna have to propagate those fixes throughout?" If I would've had to do that throughout my entire codebase (everything I'm still maintaining), there's no way I would've done it. But starting with a small project that hadn't had much built into it yet...the changes were pretty quick and painless. I don't think I've ever adopted a language tweak this quickly. I'm all in. Greatest thing is, wherever I can provide a class instance as a param to a function, and it's *not* explicitly declared as nullable, then I'm guaranteed I don't have to bother with null checks. So I'm still trying to write all functions so nulls are (explicitly) *not* allowed.

              1 Reply Last reply
              0
              • C Chris Maunder

                We do, and at first I hated it, but now I've embraced it. We find it cuts down on lots of null-ref opportunities. Sure, it can be annoying sometimes, but the occasional "!" on the end of a var, combined with the much nicer "if x is not null" makes the code very clear. Assuming you know what a trailing ! is...

                cheers Chris Maunder

                M Offline
                M Offline
                Marc Clifton
                wrote on last edited by
                #15

                Chris Maunder wrote:

                Assuming you know what a trailing ! is

                You nailed it on its ! head. Time to google. Technology keeps leaping forward and I am stumbling around trying to keep up while at the same time wondering why I'm trying to keep up. :laugh:

                Latest Articles:
                A Lightweight Thread Safe In-Memory Keyed Generic Cache Collection Service A Dynamic Where Implementation for Entity Framework

                C 1 Reply Last reply
                0
                • M Marc Clifton

                  Chris Maunder wrote:

                  Assuming you know what a trailing ! is

                  You nailed it on its ! head. Time to google. Technology keeps leaping forward and I am stumbling around trying to keep up while at the same time wondering why I'm trying to keep up. :laugh:

                  Latest Articles:
                  A Lightweight Thread Safe In-Memory Keyed Generic Cache Collection Service A Dynamic Where Implementation for Entity Framework

                  C Offline
                  C Offline
                  Chris Maunder
                  wrote on last edited by
                  #16

                  I hear ya. Reminds me of the 2 day long conversation Matthew and I had about the extra negation inif not "!arg_name:enableGPU=!" == "!arg_name!". I didn't see the double negation. He's pointing at his screen (over FaceTime) saying "there!". The issue was the "!" meant delayed expansion of a variable substitution in the Batch file, but to any reasonable developer it's "not arg_name". We imbue symbols with way too much meaning.

                  cheers Chris Maunder

                  1 Reply Last reply
                  0
                  • M Marc Clifton

                    Does anyone actually use .NET 7 with enable? I find this option makes life such a PITA that I always go into the .csproj file and disable it. The warnings are non-stop:

                    Non-nullable property 'foo' must contain a non-null value when exiting constructor. Consider declaring the property as nullable

                    Converting null literal or possible null value to non-nullable type.

                    Dereference of a possibly null reference.

                    Possible null reference assignment.

                    Nullable value type may be null.

                    And that's just a partial list, I believe. And that last one, "Nullable value type may be null" is the most amusing one. Seriously, if you have the "Nullable" option enabled, do you actually fix all those warning?

                    Latest Articles:
                    SVG Grids: Squares, Triangles, Hexagons with scrolling, sprites and simple animation examples
                    An SVG Analog Clock

                    D Offline
                    D Offline
                    dazfuller
                    wrote on last edited by
                    #17

                    All the time, and I fix the warnings if they come up. It’s greatly reduced the number of null exceptions that get thrown. I’d prefer it though if they were reported as build failures by default.

                    Eagles may soar, but weasels don't get sucked into jet engines

                    1 Reply Last reply
                    0
                    • M Marc Clifton

                      Does anyone actually use .NET 7 with enable? I find this option makes life such a PITA that I always go into the .csproj file and disable it. The warnings are non-stop:

                      Non-nullable property 'foo' must contain a non-null value when exiting constructor. Consider declaring the property as nullable

                      Converting null literal or possible null value to non-nullable type.

                      Dereference of a possibly null reference.

                      Possible null reference assignment.

                      Nullable value type may be null.

                      And that's just a partial list, I believe. And that last one, "Nullable value type may be null" is the most amusing one. Seriously, if you have the "Nullable" option enabled, do you actually fix all those warning?

                      Latest Articles:
                      SVG Grids: Squares, Triangles, Hexagons with scrolling, sprites and simple animation examples
                      An SVG Analog Clock

                      V Offline
                      V Offline
                      Vaso Elias
                      wrote on last edited by
                      #18

                      I have been using it on all of my work and hobby projects since it was introduced to .NET. #nullable #enable 🤣.

                      1 Reply Last reply
                      0
                      • M Marc Clifton

                        Does anyone actually use .NET 7 with enable? I find this option makes life such a PITA that I always go into the .csproj file and disable it. The warnings are non-stop:

                        Non-nullable property 'foo' must contain a non-null value when exiting constructor. Consider declaring the property as nullable

                        Converting null literal or possible null value to non-nullable type.

                        Dereference of a possibly null reference.

                        Possible null reference assignment.

                        Nullable value type may be null.

                        And that's just a partial list, I believe. And that last one, "Nullable value type may be null" is the most amusing one. Seriously, if you have the "Nullable" option enabled, do you actually fix all those warning?

                        Latest Articles:
                        SVG Grids: Squares, Triangles, Hexagons with scrolling, sprites and simple animation examples
                        An SVG Analog Clock

                        A Offline
                        A Offline
                        Adam ONeil Travelers Rest SC
                        wrote on last edited by
                        #19

                        Agree these warnings are pretty annoying in a project that didn't start out using nullable ref types correctly from the start. I have a large project in this situation, and fixing all these warnings is pretty daunting, requiring significant rework and refactoring. But I've come to see the value of using nullable ref types, so I've adopted it in smaller projects, and have been using it going forward. It's just not feasible to retrofit in all cases.

                        1 Reply Last reply
                        0
                        • M Marc Clifton

                          Does anyone actually use .NET 7 with enable? I find this option makes life such a PITA that I always go into the .csproj file and disable it. The warnings are non-stop:

                          Non-nullable property 'foo' must contain a non-null value when exiting constructor. Consider declaring the property as nullable

                          Converting null literal or possible null value to non-nullable type.

                          Dereference of a possibly null reference.

                          Possible null reference assignment.

                          Nullable value type may be null.

                          And that's just a partial list, I believe. And that last one, "Nullable value type may be null" is the most amusing one. Seriously, if you have the "Nullable" option enabled, do you actually fix all those warning?

                          Latest Articles:
                          SVG Grids: Squares, Triangles, Hexagons with scrolling, sprites and simple animation examples
                          An SVG Analog Clock

                          R Offline
                          R Offline
                          rallets
                          wrote on last edited by
                          #20

                          Yes, I use it, and I like it very much. Removed all possible NRE, and it's perfect to make sure juniors do not introduce tons of bugs. Sometimes a IF xx != null is enough, some other times we need "!", I hope the compiler could become smarter like Typescript is.

                          J 1 Reply Last reply
                          0
                          • M Marc Clifton

                            Does anyone actually use .NET 7 with enable? I find this option makes life such a PITA that I always go into the .csproj file and disable it. The warnings are non-stop:

                            Non-nullable property 'foo' must contain a non-null value when exiting constructor. Consider declaring the property as nullable

                            Converting null literal or possible null value to non-nullable type.

                            Dereference of a possibly null reference.

                            Possible null reference assignment.

                            Nullable value type may be null.

                            And that's just a partial list, I believe. And that last one, "Nullable value type may be null" is the most amusing one. Seriously, if you have the "Nullable" option enabled, do you actually fix all those warning?

                            Latest Articles:
                            SVG Grids: Squares, Triangles, Hexagons with scrolling, sprites and simple animation examples
                            An SVG Analog Clock

                            O Offline
                            O Offline
                            obermd
                            wrote on last edited by
                            #21

                            This entire push to eliminate Null is misguided. The reason is that in the real world sometimes you really have no information, which is what Null represents. Look at numeric data types, zero is not the same as NULL. Zero is a value but NULL represents no value. This is a fundamental semantic difference.

                            J L 2 Replies Last reply
                            0
                            • L lmoelleb

                              No one is suggesting you should not use null. The nullable check makes it explicit where you intend to use it - just as it already is for value types.

                              J Offline
                              J Offline
                              jschell
                              wrote on last edited by
                              #22

                              lmoelleb wrote:

                              makes it explicit where you intend to use it

                              Your assumption is that I do not understand what it does. You are incorrect in that assumption.

                              L 1 Reply Last reply
                              0
                              • R rallets

                                Yes, I use it, and I like it very much. Removed all possible NRE, and it's perfect to make sure juniors do not introduce tons of bugs. Sometimes a IF xx != null is enough, some other times we need "!", I hope the compiler could become smarter like Typescript is.

                                J Offline
                                J Offline
                                jschell
                                wrote on last edited by
                                #23

                                rallets wrote:

                                and it's perfect to make sure juniors do not introduce tons of bugs

                                Null pointers are not significant, to me, in production. Logic errors however are. And the only way to prevent that for juniors and seniors is meaningful code reviews.

                                1 Reply Last reply
                                0
                                • O obermd

                                  This entire push to eliminate Null is misguided. The reason is that in the real world sometimes you really have no information, which is what Null represents. Look at numeric data types, zero is not the same as NULL. Zero is a value but NULL represents no value. This is a fundamental semantic difference.

                                  J Offline
                                  J Offline
                                  jschell
                                  wrote on last edited by
                                  #24

                                  Generally the idea is thus... Someone misused it - thus it must be a problem. Then they come up with an idiom that could fix it, that single problem, while introducing other potential problems (like using magic values for no value) and then proclaim that the world is a wonderful place. Thus hoping that a technology fix can absolve them of relying on process (non-technology) solutions which have been proven (studies) to reduce problems.

                                  1 Reply Last reply
                                  0
                                  • J jschell

                                    lmoelleb wrote:

                                    makes it explicit where you intend to use it

                                    Your assumption is that I do not understand what it does. You are incorrect in that assumption.

                                    L Offline
                                    L Offline
                                    lmoelleb
                                    wrote on last edited by
                                    #25

                                    Then I misunderstood your post sorry - and I still have no idea what you where trying to say.

                                    1 Reply Last reply
                                    0
                                    • M Marc Clifton

                                      Does anyone actually use .NET 7 with enable? I find this option makes life such a PITA that I always go into the .csproj file and disable it. The warnings are non-stop:

                                      Non-nullable property 'foo' must contain a non-null value when exiting constructor. Consider declaring the property as nullable

                                      Converting null literal or possible null value to non-nullable type.

                                      Dereference of a possibly null reference.

                                      Possible null reference assignment.

                                      Nullable value type may be null.

                                      And that's just a partial list, I believe. And that last one, "Nullable value type may be null" is the most amusing one. Seriously, if you have the "Nullable" option enabled, do you actually fix all those warning?

                                      Latest Articles:
                                      SVG Grids: Squares, Triangles, Hexagons with scrolling, sprites and simple animation examples
                                      An SVG Analog Clock

                                      Y Offline
                                      Y Offline
                                      Yortw
                                      wrote on last edited by
                                      #26

                                      Not using .Net 7 yet, but using this in .Net 4.8, .Net Core 31, 5, and 6. Yeah, the warnings can be annoying, but the benefit can be significant too. Especially with junior devs who aren't used to null checking everywhere/don't have the experience to spot all the potential problems... but it's good for us oldies too, everybody misses stuff sometimes. The first warning in that list is the one that annoys me most. There are several potential work arounds depending on the specifics, but I often feel none are good :(

                                      1 Reply Last reply
                                      0
                                      • M Marc Clifton

                                        You and others are convincing me that I should just bite the bullet and fix the code. ;)

                                        Latest Articles:
                                        A Lightweight Thread Safe In-Memory Keyed Generic Cache Collection Service A Dynamic Where Implementation for Entity Framework

                                        P Offline
                                        P Offline
                                        Paul Sanders the other one
                                        wrote on last edited by
                                        #27

                                        I suppose it's a bit like `const`. You can't just sprinkle a few around the place, you have to go all-in.

                                        Paul Sanders. If I had more time, I would have written a shorter letter - Blaise Pascal. Some of my best work is in the undo buffer.

                                        1 Reply Last reply
                                        0
                                        • M Marc Clifton

                                          Does anyone actually use .NET 7 with enable? I find this option makes life such a PITA that I always go into the .csproj file and disable it. The warnings are non-stop:

                                          Non-nullable property 'foo' must contain a non-null value when exiting constructor. Consider declaring the property as nullable

                                          Converting null literal or possible null value to non-nullable type.

                                          Dereference of a possibly null reference.

                                          Possible null reference assignment.

                                          Nullable value type may be null.

                                          And that's just a partial list, I believe. And that last one, "Nullable value type may be null" is the most amusing one. Seriously, if you have the "Nullable" option enabled, do you actually fix all those warning?

                                          Latest Articles:
                                          SVG Grids: Squares, Triangles, Hexagons with scrolling, sprites and simple animation examples
                                          An SVG Analog Clock

                                          Z Offline
                                          Z Offline
                                          zezba9000
                                          wrote on last edited by
                                          #28

                                          It only makes sense for ASP.NET services or maybe new code bases that its critical you don't have null. .NETFW, Unity3D or other C# projects that heavily use older .NET frameworks its a nightmare. Only new code that uses new APIs does it work well.

                                          1 Reply Last reply
                                          0
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          • Login

                                          • Don't have an account? Register

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • World
                                          • Users
                                          • Groups