简体   繁体   English

VS Designer总是抛出异常“x属性没有get / set方法”

[英]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. 我遇到了VS Designer的这个问题,无法使用它。 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: 它发生的是我正在编辑我的XAML代码,VS Designer会在某些时候抛出异常,使用如下的StackTrace:

InvalidOperationException: The Property "MyObject.MyProperty" doesn't have a get method InvalidOperationException:属性“MyObject.MyProperty”没有get方法

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 [...] at Microsoft.Expression.DesignModel.Metadata.ClotProperty.Exign.GetVolue.Metadata.LetClpertProperty.PeritMetl.MetadataMetl上的Microsoft.Expression.DesignModel.Metadata.ClrPropertyRempleStep.GetValue(Object valueToInspect)中的Microsoft.Expression.DesignModel.Metadata.LocalClrPropertyImplementation.GetValue(Object target)。对象&值,ReferenceStep referenceStep在[...]的Microsoft.Expression.DesignModel.Metadata.PropertyReference.PartialGetValue(对象目标,Int32 initialStepIndex,Int32 finalStepIndex)上的,对象目标)

...and it goes on for another 50 lines at least. ...至少还有50行。

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. 现在,这很好用,我的项目中有很多这样的东西,VS以前从未打扰过我。 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. 如果我再次尝试关闭并打开VS,它会让我工作一段时间,然后它最终会再次开始抛出这个错误。

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? 我的意思是,我在2个月前创建了这个属性,为什么VS现在只告诉我?

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? 有没有修复此问题,或者我是否必须在我创建的每个参数中手动添加所有这些无用的get / set方法?

我认为很明显,根据你的错误信息:“属性”MyObject.MyProperty“没有get方法”,你必须通过访问MyObject.MyProperty某处使用MyProperty,你需要检查一下,还有一个方法是,如果你不想在这个类之外公开MyProperty,你应该使用'私人套装',你有一个公共二传手,你真的很奇怪你没有吸气,希望可以给你一些帮助

I have experienced windows forms designer faults (VS 2015) using write only properties (defined as write only). 我使用只写属性(定义为只写)来体验Windows窗体设计器故障(VS 2015)。 I could only get the form back on display by making the property read write (set/get). 我只能通过使属性读写(set / get)来重新显示表单。

The only reason I didn't turn this into a method was that I needed is "settable" at design time. 我没有把它变成一种方法的唯一原因是我需要的是在设计时“可设置”。

Hope this helps someone - or me when I forget and find this post again :) 希望这有助于某人 - 或者当我忘记并再次找到这篇文章时:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM