2 Comments

I’ve been working with an app which has both the Windows Phone 7.5 and the Windows Phone 8 versions. Both of these versions have their own project files which target the correct platform but they reference and use a background agent compiled as a 7.5 project. The problem: Background agent was working on the 8.0 version, but the 7.5 threw a System.InvalidOperationException when it tried to start the agent. Here’s the stack trace:

And here’s the agent:

image

The application correctly referenced the project and the WMAppManifest.xml contained the agent:

      <ExtendedTask Name="BackgroundTask">
        <BackgroundServiceAgent Specifier="ScheduledTaskAgent" Name="scheduled-agent-wp7" Source="scheduled-agent-wp7" Type="scheduled-agent-wp7.ScheduledAgent" />
      </ExtendedTask>

So what was the problem? The XML.

When you add a reference to the agent, it automatically creates the XML into the WMAppManifest.xml. But in this case, it generated the wrong XML.If you check screenshot of the code, you can see that the agent’s class is scheduled_agent_wp7.ScheduledAgent. But the generated XML tries to reference a class scheduled-agent-wp7.ScheduledAgent.

Manually fixing the WMAppManifest.xml helped to solve the issue.