I’m working on a Windows UWP webserver for hosting REST api’s. Today I tried to move from a headed to a headless demo application, but that didn’t go as smooth as I hoped.
It should be quite straight forward:
- Download the background app template
- Create a new “Background Application (IoT)” project
- Implement the StartupTask
- That’s it…
Within a few minutes I got the project ready, copied some statements from my headed app, added the deferral part and pressed F5. BAM, error:
The program ' backgroundTaskHost.exe' has exited with code 1 (0x1).
Deployment error’s, well that last time I got those I had different SDK’s on the Pi and Visual Studio. Flashed the SD card again, just to be sure I didn’t screw some settings up. Put the Pi in headless mode again and checked if msvsmon.exe (remote debugger) was running. All looked great, so let’s deploy again. Same story… this went on for hours. The most frustrating part was that this all felt too familiar, I already faced this issue before but never noted the actual solution.
In the end I found the issue, and my punctuality was my bottleneck. The way I create projects was the problem. I’m used to name the project without any namespace format, and edit the project file just after creating to fix the default namespace and assembly name. This way my project will have a short name on disk and in my solution.
The problem is this piece of xml in the Package.appxmanifest:
<Extension Category="windows.backgroundTasks" EntryPoint="BackgroundApplication1.StartupTask"> <BackgroundTasks> <iot:Task Type="startup" /> </BackgroundTasks> </Extension>
You won’t find this baby when you open the manifest in the default editor, you need the raw xml to edit this. As you can see the EntryPoint should have been edited to reflect my new namespace.