InvalidOperationException – You can only use State between OnNavigatedTo and OnNavigatedFrom

If you are receiving the below error in your Windows Phone App, have a look at the place where you are accessing the State dictionary in the Page. It could be possible that you are accessing the State dictionary within the constructor etc.

An exception of type ‘System.InvalidOperationException’ occurred in Microsoft.Phone.ni.dll but was not handled in user

Message: You can only use State between OnNavigatedTo and OnNavigatedFrom

InvalidOperationException - You can only use State between OnNavigatedTo and OnNavigatedFrom

The State dictionary in your page can only be used after the OnNavigatedTo event is called or before the OnNavigatedFrom is called. Accessing the Application State at the right time will resolve this issue.

Leave a Reply