There is an unsaved comment in progress. You will lose your changes if you continue. Are you sure you want to reopen the work item?
Navigation from CustomMessageBox Dismissed event causes NullReferenceException
Steps to reproduce:
1) Create a CustomMessageBox object.
2) Add a Dismissed event handler to this object.
3) In the Dismissed event handler, add a Navigation to another page.
4) Run the app and dismiss the CustomMessageBox. The app should throw a NullReferenceException.
What happens (from what I can understand) is the CustomMessageBox starts dismissing, runs the dismiss event as expected, then it tries to navigate, also as expected. It then gets dismissed a second time, at the end of which (the second Dismissed event), a NullReferenceException
is thrown. I believe there is some cleanup that is happening twice in this case. I will do some research in the source today and see if I can't isolate it.
For anyone else looking at this, possible fixes may include:
A try/catch in the cleanup function.
Checking for null before accessing the cleanup.
Preventing the dismiss from being called if previously dismissed, possibly by checking for navigation events.
Adding a post-Dismissed event with which to Navigate from.