Starting a BackgroundTransfer from your Background Agent

Alright, I thought I had a valid reason to start a BackgroundTransfer from my Background Agent. Sadly it doesn’t work. After a small discussion with Ilija Injac he pointed me to Unsupported APIs for Background Agents page on MSDN. Though when trying to find something based on the Exception I couldn’t find anything.

The message I got was: Operation is not valid due to the current state of the object.

With the following StackTrace:

   at Microsoft.Phone.BackgroundTransfer.BackgroundTransferRequest.SubmitHelper()
   at Microsoft.Phone.BackgroundTransfer.BackgroundTransferRequest.Submit()
   at Microsoft.Phone.BackgroundTransfer.BackgroundTransferService.Add(BackgroundTransferRequest request)
   at MC.PodCast.Common.Services.Download.DownloadService.Enqueue(Boolean eventLess)
   at MC.PodCast.Common.Services.Download.DownloadService.<Start>d__5.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
   at MC.PodCast.TaskAgent.ScheduledAgent.<<OnInvoke>b__3>d__4.MoveNext()

 

Hope this helps when you get an exception like the above. It’s just not supported to start a BackgroundTransfer from a Background Agent. Better luck next time.

Yeah Windows Phone supports Isolated Storage access through an uri-scheme! Does it?

Already some time ago, it was 2011, a new uri scheme was introduced. The isostore uri-scheme was introduced to support access to the IsolatedStorage. I’m now working on a new Windows Phone project where I have several places where I could take use of the new uri scheme.

Binding an Image Source

When you want to bind the Image Source to a remote image it can be as simple as.

<Image Source="http://someurl.com/image.png" />

 

Okay, but then we have something in the Isolated Storage.

<Image Source="isostore:/Shared/ShellContent/1.jpg" />

 

Nice, but it doesn’t work.

Creating a new BackgroundTransferRequest

The BackgroundTransferRequest has two supported constructors, one of them also allows to set the target where the downloaded file should be placed. It needs to have a Uri for the downloadLocation, so I tried a Uri containing the isostore scheme.

var request = new BackgroundTransferRequest(
    trackToEnqueue.MediaUri, 
    new Uri("isostore:/Shared/Transfers/1.mp3", UriKind.Absolute));
BackgroundTransferService.Add(request);

 

End result? Doesn’t work, sadly. I’m getting a NotSupportedException.

Alright, there are probably also a lot of places where the isostore uri-scheme is supported, the above situations at least don’t support it. Let’s see what the next update of Windows Phone will provide us.

Out of trouble! With the help of a local Windows Phone champ!

Alright, I started all the trouble myself, but wasn’t aware of it!

What I did?

I created a separate app for Windows Phone 8, similar to Windows Phone 7 but a complete new code base. At that time I also did not have interest in making the Windows Phone 8 app multilingual. The Windows Phone 8 app only supported Dutch, instead of the three languages that were supported by the Windows Phone 7 app. The expected result I thought: Windows Phone 8 will only get the Dutch app, the Windows Phone 7 users are going to get the multilingual app.

The actual result

Testing was successful, but the Windows Phone 8 specific version doesn’t appear in the Store. I didn’t know what to do, so I asked my local Windows Phone champ, Rajen Kishna. He contacted the Windows Phone team, and came back with the cause and even a solutions.

The cause

As you can see in below screenshot the supported languages are different for the two versions of the app. The Windows Phone team explained that when the language selection isn’t equal the oldest version is served.

Store details

The solution

Make sure that the language selection is equal for both apps. Probably most of us would make sure that the Windows Phone 8 app would support German and English as well. I didn’t, but the main reason for this is the business model behind the app (I’m only earning money with the Dutch version).