WP7 build error ‘Xap packaging failed’

Today my Windows Phone 7 solution started giving me one single build error:

Xap packaging failed. Object reference not set to an instance of an object.

image

Short story

A file had been removed from disk but not from the solution. Always set your sample data files to Build action: None.

Long story

The missing file

After a few rounds of clean, rebuild, machine reboot etc., I started thinking and remembered that I had replaced an image in my Expression Blend sample data and removed the old one. Looking at the solution explorer confirms this, on file missing. Excluding this file from the solution removed the problem, I can now build again. But, why would the XAP packager fail on a file only used by the sample data?

imageSolution explorer with a missing file

Build action

So, the XAP packaging failed due to a missing image file, something must be wrong. Normal build action for images used by the application should be either content or resource, see WindowsPhoneGeek – Working with images… for more info on this. But, an image what will only be used by Blend to show sample data should not be included in the build and therefore have build action: none. Changing my banner.png to Build action: None made the build go through. Of course the missing file should be excluded, but at least now we can build.

imageOriginal (faulty) build action for sample data file

Bye for now!

16 Responses to “WP7 build error ‘Xap packaging failed’”

  1. Arbind From India says:

    Very Very Thank You Sir.

    Love you so much Your simple solution solve my problem.

  2. Thanks for the nice comments people!
    /A

  3. Richard Lopes says:

    i just love you!!!!

  4. Garen says:

    oh God! Same problem occured on my project. You saved my day thanks .

  5. I ran into this exact problem, because silverlight toolkit installed from NUGET added images in the Toolkit.Content folder, which VisualHG didn’t pick up (and I didn’t either, obviously).

  6. Ayat says:

    i have the same problem now,bu i didnt know how to solve it at this way??
    i tried to delete all the pages and still the default pages but it havent been solved

  7. rajeev says:

    thanks u save my hours.

  8. Punit says:

    Thanks for the post, was facing the same issue and your post pointed me to the right direction.

  9. Thank you for commenting guys – always nice to hear that it helped someone!

  10. Rudolf says:

    Thank you I had the same problem.

  11. [...] having the correct path and are present in the project folder. Another issue may be that you are missing images of any of the referenced [...]

  12. juarola says:

    I had the same error and your post pointed me to the right direction. Actual cause was different: wrong image paths in WMAppManifest.xml. Thank you!

  13. [...] didn’t give any pointers, so i turned to Google and found this post in Jayway Team’s blog. My problem was not exactly the same, but that post pointed me to the right direction. Thank you to [...]

  14. Glad to have been of help!

  15. Cliff says:

    I ran into this problem tonight and your post helped me out! This happened to me before when I copied a WP7 project and removed files off the disk, but not out of the Solution.
    Thanks.

Leave a Reply