Error starting local setter only on release

I have a map setup that I am updating through the menu button. I have a strange situation when I just hit an error while creating releases. The code is as follows:

View Models

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

View

 <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> 

All this worked fine in my development environment, but when I created the release build, I got the following:

Error

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

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

So, why didn’t it throw an error during debugging and only during release? I do not see how this works in debug mode.

+5
source share
1 answer

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

That way, you can get this behavior if your application targets the .NET Framework 4.0, but the .NET Framework 4.5+ is installed on your development machine.

You must remove the private keyword from the installer to fix the problem.

+5
source

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


All Articles