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 Comments

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

  2. Glad to have been of help!

  3. 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!

  4. Rudolf

    Thank you I had the same problem.

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

  6. Punit

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

  7. rajeev

    thanks u save my hours.

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

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

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

  11. Richard Lopes

    i just love you!!!!

  12. Thanks for the nice comments people!
    /A

  13. Arbind From India

    Very Very Thank You Sir.

    Love you so much Your simple solution solve my problem.

Trackbacks for this post

  1. Windows Phone 7 – one fix for “Xap packaging failed. Object reference not set to an instance of an object.” « juarola's notes
  2. Resolving “Xap Packaging failed.Object reference not set to an instance of an object.” error Windows Phone 7 « Everything about MOBILES!
  3. “Xap Packaging failed. Object reference not set to an instance of an object” « candymountainsolutions

Leave a Reply