Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VS Designer always throws the Exception "The x Property doesn't have a get/set method"

I'm having this problem with the VS Designer that makes it impossible to work with it. What it happens is that I'm editing my XAML code, and the VS Designer will throw an exception at some point, with a StackTrace like this:

InvalidOperationException: The Property "MyObject.MyProperty" doesn't have a get method

StackTrace:

at Microsoft.Expression.DesignModel.Metadata.LocalClrPropertyImplementation.GetValue(Object target) at Microsoft.Expression.DesignModel.Metadata.ClrPropertyReferenceStep.GetValue(Object valueToInspect) at Microsoft.Expression.DesignModel.Metadata.PropertyReference.TryGetValue(Object& value, ReferenceStep referenceStep, Object target) at Microsoft.Expression.DesignModel.Metadata.PropertyReference.PartialGetValue(Object target, Int32 initialStepIndex, Int32 finalStepIndex) at [...]

...and it goes on for another 50 lines at least.

The Property in question is something like this:

private bool _MyProperty = true;

public bool MyProperty
{
    set
    {
        if (_MyProperty != value)
        {
            // Do a few things here
            this._MyProperty = value;
        }
    }
}

Now, this works fine, and I have dozens of things like this in my project, VS has never bothered me with them before. If I try to close and open VS again it will let me work for a while, and then it will eventually start throwing this errors again.

I tried cleaning the Solution from Compile > Clean Solution, it doesn't work.

I really don't know what's the problem here. I mean, I created that property like 2 months ago, why is VS only telling me that now?

Is there a fix for this, or do I have to manually add all those useless get/set methods in every single parameter I have created?

like image 652
Sergio0694 Avatar asked Apr 23 '15 23:04

Sergio0694


1 Answers

I think it's quite obvious, according to your error message:"The Property "MyObject.MyProperty" doesn't have a get method", you must be using MyProperty by access MyObject.MyProperty somewhere, you need to check that, and one more method is that if you don't want to expose MyProperty outside of this class, you should use 'private set', it's really odd that you don't have getter while you have a public setter,hope can give u some help

like image 80
LIU YUE Avatar answered Oct 18 '22 13:10

LIU YUE