mvvm light - MvvmLight RaisePropertyChanged error in Release builds? -


i've got weird little bug occurring under mvvmlight v4 (.net 4 build, v4.0.0.0/bl0016, installed via nuget). in project view model (which inherits viewmodelbase) represents visual element drawn on canvas. view model has typical top/left/width/height properties, each of calls raisepropertychanged, e.g.

public double width {     { return _width; }     set     {         if (math.abs(_width - value) < deltaepsilon)         {             return;         }          _width = value;         raisepropertychanged();     } } 

in response various events, view model has method calculates position , dimensions of visual element, , sets properties appropriately:

public void calculatesize() {     width = dosomecalculation();     // calculate other settings... } 

i have unit tests in place verify calculations done correctly, , when run in debug mode, tests run fine. however, if run in release mode, tests fail, following exception:

setup : system.invalidoperationexception : method can invoked within property setter. @ galasoft.mvvmlight.observableobject.raisepropertychanged() @ myproject.viewmodels.tableviewmodel.calculatesize() in tableviewmodel.cs: line 154 

where line 154 on tableviewmodel width = dosomecalculation() line. in other words, when method tries set property's value, mvvmlight complains i'm not calling raisepropertychanged within property setter. i've tried debugging test (using reshaper's test debugger), when run debugger, test passes (maybe debugging unit test in resharper forces debug mode, if in release mode already?) error occurs in application itself.

any ideas why release mode break code? there in way compiler optimises code breaks use of stacktrace in observableobject's raisepropertychanged() method? note exception above doesn't show width setter being entered, jumps straight calculatesize method exception.

if @ mvvm light code can see raisepropertychanged() uses stacktrace determine name of property. can problem in release mode described in this post.

use different raisepropertymethod circumnavigate problem - can use 1 of following methods:

raisepropertychanged<yourclass>(x => x.width); 

or

raisepropertychanged("width"); 

both methods use different method determine name of property has changed (the second uses property name).


Comments

Popular posts from this blog

c# - How to set Z index when using WPF DrawingContext? -

razor - Is this a bug in WebMatrix PageData? -

visual c++ - Using relative values in array sorting ( asm ) -