When you couple poor API documentation with dumb developer decisions you can cause developers to waste hours trying to diagnose issues with their apps. We’ve just tracked down an issue with calling CurrentApp.LoadListingInformationAsync from a Windows Store application we’re building. Whilst calling the same method on the CurrentSimulatorApp works without throwing exception, calling the method on CurrentApp throws an ArgumentException with message "Value does not fall within the expected range."
Initially we thought that this issue was related to the app not being published in the Store, so we submitted and published the app. Unfortunately the exception continues….
This thread: http://social.msdn.microsoft.com/Forums/windowsapps/en-US/0de52a76-2ec3-4b82-8d38-7385f22132f0/currentapploadlistinginformationasync-throws-argumentexception
holds the answer – you need to call this method from the UI thread.
Points to remember when building an API:
- You shouldn’t design an API that needs to run on the UI thread, that isn’t UI related
- You should document possible exceptions
- If you’re going to provide a simulator API
- The simulator should implement an interface so it can be mocked properly
- The simulator should mirror the behaviour of the real thing (in throw similar exceptions!)