私有安装员仅在发布版本上引发错误 [英] Private setter throwing error only on release build

查看:90
本文介绍了私有安装员仅在发布版本上引发错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个地图拼贴设置,我正在通过菜单按钮进行更新.我有一种奇怪的情况,我只是在发布版本中遇到错误.代码如下:

I have a map-tile setting I'm updating through a menu-button. I've got an odd situation where I was only hitting an error on release builds. Code is as follows:

视图模型

private KnownTileSource _selectedTile;
public KnownTileSource SelectedTile
{
    get { return _selectedTile; }
    private set
    {
        _selectedTile = value;
        ...
        OnPropertyChanged("SelectedTile");
    }
}

查看

<Window ...
 xmlns:predefined="clr-namespace:BruTile.Predefined;assembly=BruTile">
...
    <MenuItem Header="_Bing Aerial" Command="{Binding ChangeTileCommand}" CommandParameter="{x:Static predefined:KnownTileSource.BingAerial}" IsChecked="{Binding Path=SelectedTile, Mode=TwoWay, Converter={local:EnumToBooleanConverter}, ConverterParameter=BingAerial}"/>
...
</Window>

这一切在我的开发人员环境中都可以正常工作,但是当我生成发行版时,我得到了以下信息:

This was all working fine in my developer environment but when I generated a release build I was getting the following:

错误

System.InvalidOperationException: A TwoWay or OneWay ToSource binding cannot work on the read-only property 'SelectedTile'...

简单的解决方案,在上面的SelectedTile属性中将private set更改为set.

Simple solution, change private set to set in the above SelectedTile property.

那么,为什么在调试过程中并仅在发布过程中没有引发错误呢?我看不到它在调试模式下如何工作.

So how come this was not throwing the error during debug and only during release? I can't see how this was ever working during debug mode.

推荐答案

这是一个已修复的已知错误:

This is a known bug that has been fixed: https://connect.microsoft.com/VisualStudio/feedback/details/773682/wpf-property-with-private-setter-is-updated-by-a-twoway-binding

因此,如果您的应用程序以.NET Framework 4.0为目标,但开发计算机上安装了.NET Framework 4.5+,则可能会出现这种情况.

So you may get this behaviour if your app targets .NET Framework 4.0 but .NET Framework 4.5+ is installed on your development machine.

您应该从设置者中删除private关键字以解决此问题.

You should remove the private keyword from the setter to fix the issue.

这篇关于私有安装员仅在发布版本上引发错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆