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.
  • O Oakman

    ToddHileHoffer wrote:

    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.

    If the pay is decent and they don't require you to become a manager to get a raise, you have probably died and gone to Paradise.

    Jon Smith & Wesson: The original point and click interface

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

    Oakman wrote:

    If the pay is decent and they don't require you to become a manager to get a raise, you have probably died and gone to Paradise.

    It is not paradise, but it is a damn good job. I feel very lucky.

    I didn't get any requirements for the signature

    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

      H Offline
      H Offline
      Henry Minute
      wrote on last edited by
      #29

      Turning on the computer. At least, today it is for me. I'm having total brain fade, can hardly remember how to type, never mind code.:)

      Henry Minute Never read Medical books. You could die of a misprint. - Mark Twain

      1 Reply Last reply
      0
      • J jith iii

        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 Offline
        C Offline
        Colin Angus Mackay
        wrote on last edited by
        #30

        jith - iii wrote:

        . 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?

        There is no double standard. All reference types behave the same way. It is perfectly valid in many situations for a reference to be null. The compiler cannot catch logic errors, only syntax errors. System.Int32 is a value type. It is not valid ever for a value type to be null therefore the compiler can and will catch it for you.

        Developer Day Scotland 2 - Free community conference Recent blog posts: *Throwing Exceptions *Training Developers * Method hiding or overriding - or the difference between new and virtual

        J K A 3 Replies 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

          C Offline
          C Offline
          cpkilekofp
          wrote on last edited by
          #31

          People whose careers actually depend on the software they use often test much better than purely IT types, after going through the blood, sweat, and tears of finding out that their careers DO depend on results of the software. I've found this time and time again over the course of my career.

          T 1 Reply Last reply
          0
          • J jith iii

            :) ...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 Offline
            C Offline
            Colin Angus Mackay
            wrote on last edited by
            #32

            jith - iii wrote:

            ToString() is quite popular here. It's coming repeatedly everywhere

            Well I wish it wasn't. The number of times I've been through code written by complete Muppets who call ToString() on everything (especially on strings themselves) is depressing. I even saw someone call ToString() on an integer, pass it to a Method and for the method to Parse it back to an integer again. That method was only ever called from one place! There was no need. The quality of some code is arse-paralysingly mind blowing!

            Developer Day Scotland 2 - Free community conference Recent blog posts: *Throwing Exceptions *Training Developers * Method hiding or overriding - or the difference between new and virtual

            J C 2 Replies 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

              C Offline
              C Offline
              Colin Angus Mackay
              wrote on last edited by
              #33

              Tomz_KV wrote:

              Why ToString() can't handle the "null" automatically? It must have a good reason.

              There is a very good reason. It is because the left side of the dot operator must contain an instance of an object.

              Developer Day Scotland 2 - Free community conference Recent blog posts: *Throwing Exceptions *Training Developers * Method hiding or overriding - or the difference between new and virtual

              T 1 Reply Last reply
              0
              • T TheGreatAndPowerfulOz

                add a static extension method

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

                or simply code your ToString calls as:

                (target ?? "").ToString()

                C Offline
                C Offline
                Colin Angus Mackay
                wrote on last edited by
                #34

                ahmed zahmed wrote:

                add a static extension method

                You break the semantics of the dot operator if you do that. Crazy Extension Method[^] But there is redemption: Crazy Extension Method (redux)[^]

                Developer Day Scotland 2 - Free community conference Recent blog posts: *Throwing Exceptions *Training Developers * Method hiding or overriding - or the difference between new and virtual

                1 Reply Last reply
                0
                • C Colin Angus Mackay

                  jith - iii wrote:

                  . 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?

                  There is no double standard. All reference types behave the same way. It is perfectly valid in many situations for a reference to be null. The compiler cannot catch logic errors, only syntax errors. System.Int32 is a value type. It is not valid ever for a value type to be null therefore the compiler can and will catch it for you.

                  Developer Day Scotland 2 - Free community conference Recent blog posts: *Throwing Exceptions *Training Developers * Method hiding or overriding - or the difference between new and virtual

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

                  OMG...I was not asking a question. I was not referring the difference between value type and reference type. I think I was having a fair idea about atleast value types and reference types. Let me clarify it was not my code which has got broken here, though I also had contributed my share of null reference exception earlier. When I said I wish null.ToString() to be handled automatically,I really don't wish to be so. Why I said is the people here who code like this have fair idea abou null reference exception and they themselves have made many. Still these type of errors creep into the code and it becomes a big issue in the managerial level. I thought it would be considered as a joke. But someone has 1 voted me down.

                  modified on Tuesday, December 16, 2008 12:25 PM

                  C 1 Reply Last reply
                  0
                  • C Colin Angus Mackay

                    jith - iii wrote:

                    ToString() is quite popular here. It's coming repeatedly everywhere

                    Well I wish it wasn't. The number of times I've been through code written by complete Muppets who call ToString() on everything (especially on strings themselves) is depressing. I even saw someone call ToString() on an integer, pass it to a Method and for the method to Parse it back to an integer again. That method was only ever called from one place! There was no need. The quality of some code is arse-paralysingly mind blowing!

                    Developer Day Scotland 2 - Free community conference Recent blog posts: *Throwing Exceptions *Training Developers * Method hiding or overriding - or the difference between new and virtual

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

                    What about this code then which I have seen today written by someone.

                    Dim var1 as String=String.Format("{0}\", value1)
                    Dim var2 as String=String.Format("{0}\", value2)
                    Dim var3 as String=String.Format("{0}\", value3)
                    Dim var4 as String=String.Format("{0}\", value4)

                    Dim FinalString as String=var1+var2+var3+var4

                    PassToFunction(FinalString)

                    No tester could report a bug for this code.

                    C 1 Reply Last reply
                    0
                    • T TheGreatAndPowerfulOz

                      add a static extension method

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

                      or simply code your ToString calls as:

                      (target ?? "").ToString()

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

                      ahmed zahmed wrote:

                      (target ?? "").ToString()

                      mine is VB.Net :(. This is the first time I'm touching vb.net and it irritates. in C# after intellisence if you click "enter" it would come perfectly. But here it goes to next line and cribs. so many like this.

                      ahmed zahmed wrote:

                      ??

                      And it's .Net 2.0

                      modified on Tuesday, December 16, 2008 2:37 PM

                      1 Reply Last reply
                      0
                      • C Colin Angus Mackay

                        Tomz_KV wrote:

                        Why ToString() can't handle the "null" automatically? It must have a good reason.

                        There is a very good reason. It is because the left side of the dot operator must contain an instance of an object.

                        Developer Day Scotland 2 - Free community conference Recent blog posts: *Throwing Exceptions *Training Developers * Method hiding or overriding - or the difference between new and virtual

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

                        That is a valid reason and a designed behavior. But it is arguable if it is "good" or not. Generally speaking, null should not be handled automatically since changing nothing to something could cause more problems. However, ToString() is a special case. The expected result is a "string", either empty or not empty. If the compiler sees null.ToString(), make it an empty string. This would simplify coding and reduce a lot of errors. Just a thought. :)

                        TOMZ_KV

                        C 1 Reply 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.

                          C Offline
                          C Offline
                          chaiguy1337
                          wrote on last edited by
                          #39

                          I agree. I wish null exceptions were handled more friendly. They can be helpful while developing to identify potentially problematic or incorrect areas of code, but for end-user releases, they just end up getting in the way, since 90% of the time, just ignoring them is the solution anyway. Yet C# forces us to explicitly ignore them, rather than saving us the trouble. Look at WPF data binding as an example of how it can actually be helpful to default to ignoring: if you bind an object to a control in WPF and the object is null, WPF doesn't crash with a null reference exception, it just doesn't display anything.

                          Sad but true: 4/3 of Americans have difficulty with simple fractions. There are 10 types of people in this world: those who understand binary and those who don't. {o,o}.oO( Check out my blog! ) |)””’)          http://pihole.org/ -”-”-

                          J M 2 Replies Last reply
                          0
                          • C cpkilekofp

                            People whose careers actually depend on the software they use often test much better than purely IT types, after going through the blood, sweat, and tears of finding out that their careers DO depend on results of the software. I've found this time and time again over the course of my career.

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

                            I agree.

                            I didn't get any requirements for the signature

                            1 Reply Last reply
                            0
                            • T Tomz_KV

                              That is a valid reason and a designed behavior. But it is arguable if it is "good" or not. Generally speaking, null should not be handled automatically since changing nothing to something could cause more problems. However, ToString() is a special case. The expected result is a "string", either empty or not empty. If the compiler sees null.ToString(), make it an empty string. This would simplify coding and reduce a lot of errors. Just a thought. :)

                              TOMZ_KV

                              C Offline
                              C Offline
                              Colin Angus Mackay
                              wrote on last edited by
                              #41

                              Tomz_KV wrote:

                              But it is arguable if it is "good" or not

                              Sure. Some languages that target the .NET framework, such as Oxygene[^] do allow you to call methods using a null reference in special instances. However, these special instances are clearly visisble in the code. Oxygene does it with a colon operator rather than the dot operator. The dot operator still exists with exactly the same semantics as C# but you have the option of using the colon operator if you want to perform the operation if the reference exists, or ignore it if it doesn't. At the end of the day it is just compiler trickery because the resulting code still does the check in the CIL (MSIL)

                              Developer Day Scotland 2 - Free community conference Recent blog posts: *Throwing Exceptions *Training Developers * Method hiding or overriding - or the difference between new and virtual

                              T 1 Reply Last reply
                              0
                              • J jith iii

                                What about this code then which I have seen today written by someone.

                                Dim var1 as String=String.Format("{0}\", value1)
                                Dim var2 as String=String.Format("{0}\", value2)
                                Dim var3 as String=String.Format("{0}\", value3)
                                Dim var4 as String=String.Format("{0}\", value4)

                                Dim FinalString as String=var1+var2+var3+var4

                                PassToFunction(FinalString)

                                No tester could report a bug for this code.

                                C Offline
                                C Offline
                                Colin Angus Mackay
                                wrote on last edited by
                                #42

                                Are you calling anything on value1, value2, value3 or value4? String.Format will check if a value passed to it is null before operating on it. So, it is not really the same situation.

                                Developer Day Scotland 2 - Free community conference Recent blog posts: *Throwing Exceptions *Training Developers * Method hiding or overriding - or the difference between new and virtual

                                J F 2 Replies Last reply
                                0
                                • C Colin Angus Mackay

                                  Tomz_KV wrote:

                                  But it is arguable if it is "good" or not

                                  Sure. Some languages that target the .NET framework, such as Oxygene[^] do allow you to call methods using a null reference in special instances. However, these special instances are clearly visisble in the code. Oxygene does it with a colon operator rather than the dot operator. The dot operator still exists with exactly the same semantics as C# but you have the option of using the colon operator if you want to perform the operation if the reference exists, or ignore it if it doesn't. At the end of the day it is just compiler trickery because the resulting code still does the check in the CIL (MSIL)

                                  Developer Day Scotland 2 - Free community conference Recent blog posts: *Throwing Exceptions *Training Developers * Method hiding or overriding - or the difference between new and virtual

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

                                  Well said.

                                  TOMZ_KV

                                  1 Reply Last reply
                                  0
                                  • J jith iii

                                    OMG...I was not asking a question. I was not referring the difference between value type and reference type. I think I was having a fair idea about atleast value types and reference types. Let me clarify it was not my code which has got broken here, though I also had contributed my share of null reference exception earlier. When I said I wish null.ToString() to be handled automatically,I really don't wish to be so. Why I said is the people here who code like this have fair idea abou null reference exception and they themselves have made many. Still these type of errors creep into the code and it becomes a big issue in the managerial level. I thought it would be considered as a joke. But someone has 1 voted me down.

                                    modified on Tuesday, December 16, 2008 12:25 PM

                                    C Offline
                                    C Offline
                                    Colin Angus Mackay
                                    wrote on last edited by
                                    #44

                                    jith - iii wrote:

                                    I was not asking a question

                                    I though we were having a discussion about why things are the way they are, and specifically about the semantics of the dot operator in C#.

                                    Developer Day Scotland 2 - Free community conference Recent blog posts: *Throwing Exceptions *Training Developers * Method hiding or overriding - or the difference between new and virtual

                                    1 Reply Last reply
                                    0
                                    • C chaiguy1337

                                      I agree. I wish null exceptions were handled more friendly. They can be helpful while developing to identify potentially problematic or incorrect areas of code, but for end-user releases, they just end up getting in the way, since 90% of the time, just ignoring them is the solution anyway. Yet C# forces us to explicitly ignore them, rather than saving us the trouble. Look at WPF data binding as an example of how it can actually be helpful to default to ignoring: if you bind an object to a control in WPF and the object is null, WPF doesn't crash with a null reference exception, it just doesn't display anything.

                                      Sad but true: 4/3 of Americans have difficulty with simple fractions. There are 10 types of people in this world: those who understand binary and those who don't. {o,o}.oO( Check out my blog! ) |)””’)          http://pihole.org/ -”-”-

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

                                      What is specific to this error is,people who has enough experience in .Net also carelessly makes this mistake. And just by looking at the error message any other technical person can identify that the developer has tried to perform something with null. Since this is a basic rule, the shame this error makes will sometimes be very much.

                                      C 1 Reply Last reply
                                      0
                                      • J jith iii

                                        What is specific to this error is,people who has enough experience in .Net also carelessly makes this mistake. And just by looking at the error message any other technical person can identify that the developer has tried to perform something with null. Since this is a basic rule, the shame this error makes will sometimes be very much.

                                        C Offline
                                        C Offline
                                        chaiguy1337
                                        wrote on last edited by
                                        #46

                                        What strikes me, is that if developers (even experienced ones) are still making this "mistake", then it indicates a conflict in how developers think versus how the compiler "thinks". In other words, it doesn't necessarily mean that the developer doesn't know what they're doing. When I design and write methods, etc., I usually assume that the object I'm working with is alive and non-null, yet later on I may set a certain property or field to null because it no longer applies. If it doesn't apply, then naturally neither does any operation that would affect that object, and therefore even if I didn't originally intend or expect to set that property or field to null, the fact that I later decide to should not break my existing code that assumes it is alive! Just to give a concrete example of how this might be the case, suppose I have some logging window that keeps track of debugging output while I'm running my program, and throughout the development process this window is always open, or at least exists and is maybe invisible. But when I start my optimizing phase, I no longer want to keep that debug window open all the time, consuming resources the end user doesn't need. However, in my code, I originally assumed it was alive, and did something like this: myApp.DebugWindow.WriteLine( "foo" ); Sure you could argue (and many will) that this is poor programming and I should in fact precede every statement with "if ( myApp.DebugWindow != null )" but frankly in my opinion this is just additional work that needs to be done that doesn't really affect the intended behavior of the program. If I set myApp.DebugWindow to null, then at least when running in release mode, any null reference exceptions should simply be absorbed by the runtime. There is no excuse to crash the whole application for something as silly as forgetting to prefix a statement with an "!= null" check first. Granted, there are ways one could do this, by installing a handler and checking for null reference exceptions, and explicitly setting them to handled (in fact that might be a good practice in general), but again this is more work and the whole point here is to make the language much friendlier with imperfectly-specified programs. I know a lot of people will disagree with me on this one; but I'm all about software working as well as it possibly can, and not crashing and disrupting the user for things that aren't important. Everyone strives for "perfect" software, but it shouldn't be a requirement of the language.

                                        1 Reply Last reply
                                        0
                                        • C Colin Angus Mackay

                                          jith - iii wrote:

                                          ToString() is quite popular here. It's coming repeatedly everywhere

                                          Well I wish it wasn't. The number of times I've been through code written by complete Muppets who call ToString() on everything (especially on strings themselves) is depressing. I even saw someone call ToString() on an integer, pass it to a Method and for the method to Parse it back to an integer again. That method was only ever called from one place! There was no need. The quality of some code is arse-paralysingly mind blowing!

                                          Developer Day Scotland 2 - Free community conference Recent blog posts: *Throwing Exceptions *Training Developers * Method hiding or overriding - or the difference between new and virtual

                                          C Offline
                                          C Offline
                                          chaiguy1337
                                          wrote on last edited by
                                          #47

                                          Colin Angus Mackay wrote:

                                          I even saw someone call ToString() on an integer, pass it to a Method and for the method to Parse it back to an integer again. That method was only ever called from one place!

                                          lol

                                          Sad but true: 4/3 of Americans have difficulty with simple fractions. There are 10 types of people in this world: those who understand binary and those who don't. {o,o}.oO( Check out my blog! ) |)””’)          http://pihole.org/ -”-”-

                                          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