VS Designer always throws an exception "Property x does not have a get / set method"

I had a problem with VS Designer, which makes it impossible to work with it. What happens is that I am editing my XAML code, and VS Designer at some point throws an exception, with StackTrace looking like this:

InvalidOperationException: property "MyObject.MyProperty" does not have a get method

Stacktrace:

in Microsoft.Expression.DesignModel.Metadata.LocalClrPropertyImplementation.GetValue (object-object) in Microsoft.Expression.DesignModel.Metadata.ClrPropertyReferenceStep.GetValue (Object valueToInspect) in Microsoft.Expression.DesignModel.Metetate.Proet.Proet.Proet.Proet.Proment.Proetty.Proet.Proetty.Proet.Product.Pro ReferenceStep referenceStep, Object target) in Microsoft.Expression.DesignModel.Metadata.PropertyReference.PartialGetValue (Object target, Int32 initialStepIndex, Int32 finalStepIndex) in [...]

... and it continues for another 50 lines.

The corresponding property looks something like this:

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

Now it works great, and I have 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 allow me to work for a while, and then it will again start throwing these errors again.

I tried to clear the solution from compilation> Clean Solution, it does not work.

I really don't know what the problem is. I mean, I created this property like 2 months ago, why does VS just tell me what now?

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

+6
source share
2 answers

I think this is quite obvious, according to your error message: "The MyObject.MyProperty property" does not have a get method ", you should use MyProperty by accessing MyObject.MyProperty somewhere, you need to check, and another method is to that if you do not want to expose MyProperty outside this class, you should use a "private set", it is really strange that you do not have a getter, as long as you have a public setter, hope can give you some help

+1
source

I am having Windows Forms Designer errors (VS 2015) using write properties (write only). I could only return the form to the display by making the read write (set / get) property.

The only reason I didn't turn this into a method was because I needed to "tune" during development.

Hope this helps someone - or me, when I forget and find this post again :)

0
source

Source: https://habr.com/ru/post/985829/


All Articles