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.


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!

This Post Has 17 Comments

  1. Cliff

    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.

  2. juarola

    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!

  3. Rudolf

    Thank you I had the same problem.

  4. Andreas Hammar

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

  5. Punit

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

  6. rajeev

    thanks u save my hours.

  7. Ayat

    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

  8. Anders Poulsen

    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).

  9. Garen

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

  10. Richard Lopes

    i just love you!!!!

  11. Arbind From India

    Very Very Thank You Sir.

    Love you so much Your simple solution solve my problem.

  12. Taha

    Thank you sir.

Leave a Reply