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

                D Offline
                D Offline
                dan sh
                wrote on last edited by
                #21

                334,000 google search results for the error message(with quotes). It surely is the most popular

                C isn't that hard: void (*(*f[])())() defines f as an array of unspecified size, of pointers to functions that return pointers to functions that return void "Always program as if the person who will be maintaining your program is a violent psychopath that knows where you live." - Martin Golding

                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()

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

                  I've been using (target==null?"":target).ToString( :) ) so far. ?? is a nicer.

                  TOMZ_KV

                  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

                    M Offline
                    M Offline
                    MidwestLimey
                    wrote on last edited by
                    #23

                    ToddHileHoffer wrote:

                    It has been live for six weeks now without one bug or code change required

                    You do realize no one is using it, don't you?

                    Bar fomos edo pariyart gedeem, agreo eo dranem abal edyero eyrem kalm kareore

                    T 1 Reply Last reply
                    0
                    • M MidwestLimey

                      ToddHileHoffer wrote:

                      It has been live for six weeks now without one bug or code change required

                      You do realize no one is using it, don't you?

                      Bar fomos edo pariyart gedeem, agreo eo dranem abal edyero eyrem kalm kareore

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

                      MidwestLimey wrote:

                      You do realize no one is using it, don't you?

                      That is what I thought at first. After the second day of it being in production I had to check the database to see what was up. I hadn't gotten any emails from the error handler. I thought either the error handler is busted or they were not using it.

                      I didn't get any requirements for the signature

                      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.

                        N Offline
                        N Offline
                        Nemanja Trifunovic
                        wrote on last edited by
                        #25

                        Super Lloyd wrote:

                        ObjectiveC is a beast of its own... It's even legal to call method which don't exist!

                        ObjectiveC is an attempt to turn C into SmallTalk.

                        Programming Blog utf8-cpp

                        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

                          N Offline
                          N Offline
                          Nemanja Trifunovic
                          wrote on last edited by
                          #26

                          Rama Krishna Vavilala wrote:

                          in Objective C where it is legal to invoke methods on nulls

                          It is legal in C++ too, and in some weird cases can be even safe :)

                          Programming Blog utf8-cpp

                          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

                            O Offline
                            O Offline
                            Oakman
                            wrote on last edited by
                            #27

                            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 1 Reply Last reply
                            0
                            • 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
                                          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