Windows Phone

BNS Error: The action request has expired

When using Background Agents in Windows Phone you may experience an InvalidOperationException with the message ‘BNS Error: The action request has expired‘ like so:

BNS Error: The action request has expired

This error means that your background task either threw an exception or failed to call NotifyComplete(). This error will not go away once you’ve fixed the issue – the background task must be removed. You can either do this in code, or uninstall the app and install it again.

Posted by Dan in Windows Phone, 0 comments

InvalidOperationException and FileNotFoundException with Background Tasks in Windows Phone

There are a few Exceptions Windows Phone throws when a Background Task isn’t correctly configured, sadly they’re very misleading. In this blog post I’ll outline some of the common exceptions you’ll get and how to go about fixing them.

Failure to Run

When you call ‘ScheduledActionService.LaunchForTest’ you may get an InvalidOperationException like so:

InvalidOperationException on LaunchForTest

This Exception means you haven’t added the ExtendedTask info in the WMAppManifest.xml file (found in ‘Properties’). Open the file in the XML editor (right-click on it and select ‘Open With’), and make sure you’ve entered the ExtendedTask info:

<Tasks>
  <DefaultTask  Name ="_default" NavigationPage="MainPage.xaml"/>
  <ExtendedTask Name="BackgroundTask">
    <BackgroundServiceAgent Specifier="ScheduledTaskAgent" Name="TileUpdateAgent" Source="WP7LiveTileDemo" Type="WP7LiveTileDemo.Agents.TileUpdateAgent" />
  </ExtendedTask>
</Tasks>

The values are as follows:

  • Specifier – The type of background agent, you can only have one of each type
  • Name – Name for this task, can be anything you like
  • Source – The name of the Assembly (without the .dll extension) that contains the agent. If this is wrong you’ll get both InvalidOperationException and FileNotFoundException exceptions
  • Type – The full class name (ie. must include the namespace path too) of the agent you set up in code. If this is wrong you’ll get an InvalidOperationException

InvalidOperationException and/or FileNotFoundException

If anything is wrong with the ExtendedTask declaration you’ll get InvalidOperationException or FileNotFoundException being thrown from Microsoft.Phone.ni.dll, it’ll look something like this:

InvalidOperationException from a BackgroundTask in WP InvalidOperationException stack trace from a BackgroundTask in WP

Make sure to double-check your ExtendedTask XML is perfect, especially the Source and Type attributes.

Posted by Dan in Windows Phone, 1 comment

Windows Phone app closes as soon as it opens

I was recently having a problem with an app closing as soon as it started, with absolutely no error messages at all. Turns out, the ‘Startup object’ value had been cleared, leaving it at the default ‘not set’. Setting it back to the name of the Application sorted it:

Startup object selection in Visual Studio

Posted by Dan in Programming, Windows Phone, 0 comments