Weird StackTrace behaviour

A colleague noticed that changing a combobox wasn’t showing the changes in the text fields below.
When testing, I saw it WAS working. But with the click-once application not.
After some time I noticed running the release without visual studio, it didn’t work.
Although it worked when running with visual studio. Also the debug version was working.

For binding the text fields to my object I simply used a property: “Regime”.
The (work)regime has 10 properties: id, user(id), “Monday” till “Sunday” and “weektotal”.
All these properties raise an event by calling “PropChanged()”.
This method would look up into the call stack which method called him. Properties get set_ and get_ before the property-name as method.
This way I could test it was ending with “day” and then also raise a “weektotal”-changed event, as this property is read-only and actually a property for binding the total of all days.

  1. Private Sub PropChanged()
  2. 'Get the stacktrace and get the calling method
  3. Dim stack As Diagnostics.StackTrace = New System.Diagnostics.StackTrace
  4. Dim method As Reflection.MethodBase = stack.GetFrame(1).GetMethod()
  5. 'Methods starting with "set_" are the properties
  6. If method.Name.ToLower.StartsWith("set_") Then
  7. 'remove the "set_" and raise the event with the propertyname
  8. RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(method.Name.Substring(4)))
  9. 'when the day changes, the total is also changed
  10. If method.Name.EndsWith("day") Then
  11. RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs("weektotal"))
  12. End If
  13. End If
  14. End Sub

In a combobox I had a list of “presets” and when I select one, I update the “Regime”, to have the same values. Now, this wasn’t working.
After like testing everything, for fun I showed a messagebox with the method.Name property.
This let only see: “.createWorkRegime”, a complete surprise as it was actualy called by the Property “Monday” or “Tuesday” etc.

Obvious, when adding the plain RaiseEvent PropertyChanged, the binding works.
I didn’t figured out why this happens, but it looks like the call-stack is changed when using properties in the constructor.
I really don’t understand it as it’s only having this behaviour when used in the constructor.

So it is changing the call stack AND ONLY when its executed from release (and directly the exe and not by visual studio)

If someone knows why this is happening, please let me know.