Saturday 22 January 2011

Windows Phone 7: Security Exception on deactivate

This morning I have been finishing the tombstoning part of one of my Windows Phone applications I have been developing. Whilst testing I found that when the application deactivated or terminated that a SecurityException was thrown. Looking at the stack trace I noticed that it was occurring whilst trying to serialise some data to the Applications State store.


Now I knew I was putting some data into state so this wasn't to hard to find however, when I looked at what I was putting into state it was nothing more complicated than a custom type that exposed a collection of POCO classes. Why would this cause a security exception.


I decided to do a simple Google search for the exception "windows phone 7 security exception" and the second result looked similar: "c# - SecurityException was unhandled when using isolated storage" [http://stackoverflow.com/questions/4209280/securityexception-was-unhandled-when-using-isolated-storage]. So I had a look, and guessed that if you can't put internal classes into IsolatedStorage you also can't do it for ApplicationState, which makes sense when you think about it. So I made my type public and not internal and all was good in the world again.


Another week another tip.... I wonder what I will find out next week

No comments: