- Kim Bach . Org - http://www.kimbach.org -

No _compiler_ detected errors – but shouldn’t I, at least, have received a warning?

Posted By Kim On December 19, 2007 @ 8:00 pm In Blogs,Computere og Internet,Historier/Stories,Kim Blog (English),Technology | No Comments

One of the first compilers I worked with, VS-Pascal, had a very “HAL-like” confident behaviour, after it had finished a succesful compile, it wrote:

“No compiler detected errors”

I found that almost rude, but it was also something to keep in the back of your mind, and today I remembered this clearly.

For the last week or so I’ve had a mysterious ASP.NET/C# problem on the back-burner. I’m trying to populate a drop-down list on a webpage. The list is based on a list of documents. For that purpose I had an entity class with a constructor, in the Page_Load code of the webform, I’m initialising the drop-down with a desciption and an id from the document list.

The list was populated just fine, but when I did a post of the form, I was consistently told that the first item was selected, even if I selected item number 2, 3 or 4.

This was very frustrating, especially because I have two drop-downs, and the other was working just fine.

Today I couldn’t postpone the problem any longer, and I tried a number of things, including moving the drop-downs, and finally I started doing websearches for bug-reports, but it’s extremely unlikely that ASP.NET has such a fundamental bug, so I was clearly doing something wrong.

When you’re using frameworks like .NET, a lot is done behind the scenes, luckily I know HTML so I finally hit View/Source, and to my surprise all the option values in the select tag were set to 0, why was that, I knew that my list was initialised to values from 0-4, but it was consistent with the test-results.

I was clearly doing something wrong. Below is the C# source-code for the entity class, can you spot the problem?

public class ShredYearDocument
   {
       private int _shredYearId;

       public int ShredYearId
       {
           get { return _shredYearId; }
           set { _shredYearId = value; }
       }

       string _shredYearDescription;

       public string ShredYearDescription
       {
           get { return _shredYearDescription; }
           set { _shredYearDescription = value; }
       }

       public ShredYearDocument(int ShredYeadId, 
           string ShredYearDescription)
       {
           _shredYearId = ShredYearId;
           _shredYearDescription = ShredYearDescription;
       }
   }

I’ll give you a hint: there are no compiler detected errors, but I’d argue that the compiler should,at least, have generated a warning, because I have something that could be likened to unused, or uninitalised, local variables.

Another hint: Remember that I always had the id set to zero (0), no mater what.

But shouldn’t the compiler generate a warning here?


Article printed from Kim Bach . Org: http://www.kimbach.org

URL to article: http://www.kimbach.org/2007/12/19/no-_compiler_-detected-errors-but-shouldnt-i-at-least-have-recieved-a-warning/

URLs in this post:

[1] : http://www.kimbach.org/2007/12/19/no-_compiler_-detected-errors-but-shouldnt-i-at-least-have-recieved-a-warning/?share=facebook

[2] : http://www.kimbach.org/2007/12/19/no-_compiler_-detected-errors-but-shouldnt-i-at-least-have-recieved-a-warning/?share=twitter

[3] : http://www.kimbach.org/2007/12/19/no-_compiler_-detected-errors-but-shouldnt-i-at-least-have-recieved-a-warning/?share=google-plus-1

[4] : http://www.kimbach.org/2007/12/19/no-_compiler_-detected-errors-but-shouldnt-i-at-least-have-recieved-a-warning/?share=tumblr

[5] : http://www.kimbach.org/2007/12/19/no-_compiler_-detected-errors-but-shouldnt-i-at-least-have-recieved-a-warning/?share=pinterest

[6] : http://www.kimbach.org/2007/12/19/no-_compiler_-detected-errors-but-shouldnt-i-at-least-have-recieved-a-warning/#print

[7] : http://www.kimbach.org/2007/12/19/no-_compiler_-detected-errors-but-shouldnt-i-at-least-have-recieved-a-warning/?share=email