Wednesday 18 March 2009

Silverlight: OOB: Detach, user cancelling and exceptions

So there is a couple of things I want you to be aware of when detaching your Silverlight application

App.Current.Detach() returns a boolean

If the user selects cancel, then it will return false, otherwise it will return true.  You need to check for this, rather than assuming it worked.

Exceptions if you are already detached

You will receive a very nice InvalidOperationException with a message stating your application is already detached (if you attempt to detach your application, and you are already detached).

You need to catch this, you can't test for this in the Execution State, because if the user has installed, and then uninstalled your application straight away, but then decides to install it once more, in the same instance, then your "In Browser" application will believe you are detached when you are not.

Exceptions (badly), if you detach and you are not detachable

If you attempt to detach (via code), and your application is not detachable (you didn't setup the xml in your manifest).  SL3 will throw a big wobbly, be careful.

No comments: