locked
Properties don't work? RRS feed

  • Question

  • I have a serious problem and I have no clue how it can even be possible.

    I have written a class and when trying to debug the properties, I realized that the code never actually reaches them.

    My class has a protected int attribute, with a normal public int property.

    However, I instantiated an object of the class (code does step into the constructor) and then assigned the int property several new value, but the break point I've set inside the setter of the property never get reached and the program never stops there.

    What could be the casue, and how can I fix this problem?

    Thanks.

    Monday, July 25, 2011 6:20 AM

Answers

  • In Visual Studio 2008 anyway, you can go to Tools/Options/Debugging/General and disable Step Over properties and operators(Managed Only) that might help you to track down the problem.
    • Proposed as answer by Matthew Watson Monday, July 25, 2011 2:00 PM
    • Marked as answer by Cookie Luo Wednesday, August 3, 2011 6:00 AM
    Monday, July 25, 2011 10:43 AM

All replies

  • Could you please provide some code? Then we can have a closer look at it and maybe find your error. With your description at least I do not see the general problem.

    With kind regards,

    Konrad

    Monday, July 25, 2011 7:01 AM
  • This is my class (short version, the original has over 1000 lines but this is the full extent of the property I'm talking about)

    public class Actor
    {
      protected int id;
    
      public int ID
      {
        get { return this.id; }
        set { 
             if (value < 0)
             {
                throw new Exception ("ERROR");
             }
              
             else
             {
                this.id = value
             }
           }
      }
    }
    
    
    
    
    


    And this is the code I used in the form where I create an Actor object:

    //. . . other, irrelevant code
    Actor a = new Actor();
    a.ID = 0;
    a.ID += 50;
    a.ID -= 5;
    a.ID = -100;
    //. . . other, irrelevant code
    

    Not only did I set break points all of the property, but I also caused it to throw an exception - in theory. In praxis, the exception does not get thrown as all code inside the property (at least the setter) is ignored.

     

     

    Monday, July 25, 2011 8:35 AM
  • Is this Actor class in a DLL?


    Please mark this post as answer if it solved your problem. Happy Programming!
    Monday, July 25, 2011 8:46 AM
  • In Visual Studio 2008 anyway, you can go to Tools/Options/Debugging/General and disable Step Over properties and operators(Managed Only) that might help you to track down the problem.
    • Proposed as answer by Matthew Watson Monday, July 25, 2011 2:00 PM
    • Marked as answer by Cookie Luo Wednesday, August 3, 2011 6:00 AM
    Monday, July 25, 2011 10:43 AM
  • I don't think he has problems with VS settings. Because, he is not only able to hit the breakpoint, but also the property also not getting executed (He says he is trying to throw an exception but it is not throwing any exception at all)

    So, I think he has this code in dll. Then added the project to solution but he is refrencing the DLL but not project. So the break point is never hit and also the changes to the property are never executed because the DLL he is refering to is different.

    (Hope my assumption is correct)


    Please mark this post as answer if it solved your problem. Happy Programming!
    Monday, July 25, 2011 4:37 PM
  • I was thinking that way he can step into the property setter. 
    Monday, July 25, 2011 4:44 PM