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. What is the most common error in a .Net application?

What is the most common error in a .Net application?

Scheduled Pinned Locked Moved The Lounge
questioncsharphelp
59 Posts 26 Posters 10 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.
  • J Offline
    J Offline
    jith iii
    wrote on last edited by
    #1

    Last week we had a code delivery. We have been taught from the graduation days that ToString() without a null check is a bomb. Still we got it in a critical part . "Object reference not set" My vote goes for it.

    modified on Monday, December 15, 2008 2:26 PM

    R L S T T 8 Replies Last reply
    0
    • J jith iii

      Last week we had a code delivery. We have been taught from the graduation days that ToString() without a null check is a bomb. Still we got it in a critical part . "Object reference not set" My vote goes for it.

      modified on Monday, December 15, 2008 2:26 PM

      R Offline
      R Offline
      realJSOP
      wrote on last edited by
      #2

      I vote for the part where the user is given a chance to enter data. If a program is going to crash, that's most likely going to be the reason.

      "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
      -----
      "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001

      G 1 Reply Last reply
      0
      • J jith iii

        Last week we had a code delivery. We have been taught from the graduation days that ToString() without a null check is a bomb. Still we got it in a critical part . "Object reference not set" My vote goes for it.

        modified on Monday, December 15, 2008 2:26 PM

        L Offline
        L Offline
        leppie
        wrote on last edited by
        #3

        This is the most common error for most languages that support null/NULL reference assignment.

        xacc.ide - now with TabsToSpaces support
        IronScheme - 1.0 beta 1 - out now!
        ((lambda (x) `((lambda (x) ,x) ',x)) '`((lambda (x) ,x) ',x))

        J 1 Reply Last reply
        0
        • J jith iii

          Last week we had a code delivery. We have been taught from the graduation days that ToString() without a null check is a bomb. Still we got it in a critical part . "Object reference not set" My vote goes for it.

          modified on Monday, December 15, 2008 2:26 PM

          S Offline
          S Offline
          Super Lloyd
          wrote on last edited by
          #4

          And what about Trim()? Hehe... Just want to point out that the very limited scope of your warning is funny! ;P Any method can potentially fire a null reference exception hey! :-D

          A train station is where the train stops. A bus station is where the bus stops. On my desk, I have a work station.... _________________________________________________________ My programs never have bugs, they just develop random features.

          J 1 Reply Last reply
          0
          • J jith iii

            Last week we had a code delivery. We have been taught from the graduation days that ToString() without a null check is a bomb. Still we got it in a critical part . "Object reference not set" My vote goes for it.

            modified on Monday, December 15, 2008 2:26 PM

            T Offline
            T Offline
            ToddHileHoffer
            wrote on last edited by
            #5

            In .net it is the classic "object reference not set to an instance of an object". Speaking of bugs, I started a new position back in June. This company (not an IT company) does an amazing job of testing. The first application I did here was coded in about 4 weeks by myself and a consultant. The company used the application in test for an entire month before we rolled it out. It has been live for six weeks now without one bug or code change required. This is the first time, I have accomplished this.

            I didn't get any requirements for the signature

            P D M O C 5 Replies Last reply
            0
            • L leppie

              This is the most common error for most languages that support null/NULL reference assignment.

              xacc.ide - now with TabsToSpaces support
              IronScheme - 1.0 beta 1 - out now!
              ((lambda (x) `((lambda (x) ,x) ',x)) '`((lambda (x) ,x) ',x))

              J Offline
              J Offline
              jith iii
              wrote on last edited by
              #6

              If you can assign null to a string,why the hell they are not making null.ToString() atleast null without cribbing. I hate the concept of null considering the harm this error caused to our delivery.

              R C 2 Replies Last reply
              0
              • S Super Lloyd

                And what about Trim()? Hehe... Just want to point out that the very limited scope of your warning is funny! ;P Any method can potentially fire a null reference exception hey! :-D

                A train station is where the train stops. A bus station is where the bus stops. On my desk, I have a work station.... _________________________________________________________ My programs never have bugs, they just develop random features.

                J Offline
                J Offline
                jith iii
                wrote on last edited by
                #7

                :) ...but I don't know, ToString() is quite popular here. It's coming repeatedly everywhere. May be,people Trim() only after they polish the null refernece with ToString()

                C O 2 Replies Last reply
                0
                • J jith iii

                  Last week we had a code delivery. We have been taught from the graduation days that ToString() without a null check is a bomb. Still we got it in a critical part . "Object reference not set" My vote goes for it.

                  modified on Monday, December 15, 2008 2:26 PM

                  T Offline
                  T Offline
                  Tomz_KV
                  wrote on last edited by
                  #8

                  That is something I do not understand. Why ToString() can't handle the "null" automatically? It must have a good reason.

                  TOMZ_KV

                  R T C 3 Replies Last reply
                  0
                  • J jith iii

                    If you can assign null to a string,why the hell they are not making null.ToString() atleast null without cribbing. I hate the concept of null considering the harm this error caused to our delivery.

                    R Offline
                    R Offline
                    Rob Graham
                    wrote on last edited by
                    #9

                    jith - iii wrote:

                    If you can assign null to a string,

                    You're not assigning null to a string. You're setting a reference to a string to null (meaning it refers to nothing), not at all the same thing. You are forgetting that strings are reference types, not value types. Since the null is an invalid reference, there is nothing (no class instance or static object) which might implement ToString(), hence the null reference exception.

                    T J 2 Replies Last reply
                    0
                    • R realJSOP

                      I vote for the part where the user is given a chance to enter data. If a program is going to crash, that's most likely going to be the reason.

                      "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
                      -----
                      "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001

                      G Offline
                      G Offline
                      Gary Wheeler
                      wrote on last edited by
                      #10

                      My approach is to strike first.

                      Software Zen: delete this;

                      1 Reply Last reply
                      0
                      • T Tomz_KV

                        That is something I do not understand. Why ToString() can't handle the "null" automatically? It must have a good reason.

                        TOMZ_KV

                        R Offline
                        R Offline
                        Rob Graham
                        wrote on last edited by
                        #11

                        It's similar to an uninitialized pointer in C++. It's just the address of an object (which if null is an invalid address), nothing exists to implement the method.

                        1 Reply Last reply
                        0
                        • T ToddHileHoffer

                          In .net it is the classic "object reference not set to an instance of an object". Speaking of bugs, I started a new position back in June. This company (not an IT company) does an amazing job of testing. The first application I did here was coded in about 4 weeks by myself and a consultant. The company used the application in test for an entire month before we rolled it out. It has been live for six weeks now without one bug or code change required. This is the first time, I have accomplished this.

                          I didn't get any requirements for the signature

                          P Offline
                          P Offline
                          PJ Arends
                          wrote on last edited by
                          #12

                          Quick! Knock on wood. Now that you mentioned it out in the open, the bug reports will come swarming in.


                          You may be right I may be crazy -- Billy Joel -- Within you lies the power for good - Use it!

                          1 Reply Last reply
                          0
                          • J jith iii

                            Last week we had a code delivery. We have been taught from the graduation days that ToString() without a null check is a bomb. Still we got it in a critical part . "Object reference not set" My vote goes for it.

                            modified on Monday, December 15, 2008 2:26 PM

                            R Offline
                            R Offline
                            Rama Krishna Vavilala
                            wrote on last edited by
                            #13

                            You should program in Objective C where it is legal to invoke methods on nulls.

                            id v = nil;
                            NSString* valueAsString = [v description];

                            modified on Monday, December 15, 2008 2:58 PM

                            R S N 3 Replies Last reply
                            0
                            • R Rama Krishna Vavilala

                              You should program in Objective C where it is legal to invoke methods on nulls.

                              id v = nil;
                              NSString* valueAsString = [v description];

                              modified on Monday, December 15, 2008 2:58 PM

                              R Offline
                              R Offline
                              Rob Graham
                              wrote on last edited by
                              #14

                              Would his code have been any less broken?

                              R 1 Reply Last reply
                              0
                              • R Rama Krishna Vavilala

                                You should program in Objective C where it is legal to invoke methods on nulls.

                                id v = nil;
                                NSString* valueAsString = [v description];

                                modified on Monday, December 15, 2008 2:58 PM

                                S Offline
                                S Offline
                                Super Lloyd
                                wrote on last edited by
                                #15

                                ObjectiveC is a beast of its own... It's even legal to call method which don't exist! Who knows, a Forward or a Category might even intercept them?

                                A train station is where the train stops. A bus station is where the bus stops. On my desk, I have a work station.... _________________________________________________________ My programs never have bugs, they just develop random features.

                                R N 2 Replies Last reply
                                0
                                • R Rob Graham

                                  Would his code have been any less broken?

                                  R Offline
                                  R Offline
                                  Rama Krishna Vavilala
                                  wrote on last edited by
                                  #16

                                  It Depends:).

                                  1 Reply Last reply
                                  0
                                  • S Super Lloyd

                                    ObjectiveC is a beast of its own... It's even legal to call method which don't exist! Who knows, a Forward or a Category might even intercept them?

                                    A train station is where the train stops. A bus station is where the bus stops. On my desk, I have a work station.... _________________________________________________________ My programs never have bugs, they just develop random features.

                                    R Offline
                                    R Offline
                                    Rama Krishna Vavilala
                                    wrote on last edited by
                                    #17

                                    Super Lloyd wrote:

                                    It's even legal to call method which don't exist!

                                    Yes and this feature has its own strengths (and weaknesses).

                                    1 Reply Last reply
                                    0
                                    • R Rob Graham

                                      jith - iii wrote:

                                      If you can assign null to a string,

                                      You're not assigning null to a string. You're setting a reference to a string to null (meaning it refers to nothing), not at all the same thing. You are forgetting that strings are reference types, not value types. Since the null is an invalid reference, there is nothing (no class instance or static object) which might implement ToString(), hence the null reference exception.

                                      T Offline
                                      T Offline
                                      TheGreatAndPowerfulOz
                                      wrote on last edited by
                                      #18

                                      in C++, the target function actually gets called and so long as no reference is made to instance variables in that function, no null reference will occur due to the null 'this' (obviously, something else could be null). So, a somewhat common tactic is to test for "this == null" or "this != null".

                                      1 Reply Last reply
                                      0
                                      • T Tomz_KV

                                        That is something I do not understand. Why ToString() can't handle the "null" automatically? It must have a good reason.

                                        TOMZ_KV

                                        T Offline
                                        T Offline
                                        TheGreatAndPowerfulOz
                                        wrote on last edited by
                                        #19

                                        add a static extension method

                                        string string.ToString(string target)
                                        {
                                        return (target ?? "").ToString();
                                        }

                                        or simply code your ToString calls as:

                                        (target ?? "").ToString()

                                        T C J 3 Replies Last reply
                                        0
                                        • R Rob Graham

                                          jith - iii wrote:

                                          If you can assign null to a string,

                                          You're not assigning null to a string. You're setting a reference to a string to null (meaning it refers to nothing), not at all the same thing. You are forgetting that strings are reference types, not value types. Since the null is an invalid reference, there is nothing (no class instance or static object) which might implement ToString(), hence the null reference exception.

                                          J Offline
                                          J Offline
                                          jith iii
                                          wrote on last edited by
                                          #20

                                          well,grammer may be wrong,but I meant the same. It will instantly give error if you try to set null to an integer,right? why double standard to string where you can set it to nothing but not otherwise? :) (Just consider this as an emotional outburst. I don't really want to excuse people forgetting a null check)

                                          C 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