title: What is behind a silent failure to load resource on x64 bit machine with .NET 4.0?
body: <p>A user of my program has reported an inability to startup the application. I am not yet done troubleshooting, but I'm simply baffled.</p>
  
  <p>Logging still works, so I used logging statements and was able to narrow down the crash to a single line in a user control's InitializeComponent:</p>
  
  <blockquote>
    <p>this.HorizontalBox.Image =
    ((System.Drawing.Image)(resources.GetObject("HorizontalBox.Image")));</p>
  </blockquote>
  
  <p>Here are the relevant clues from his end:</p>
  
  <ul>
  <li>64 bit Windows 7</li>
  <li>Correct .NET Framework (4.0 Client Profile)</li>
  <li>No visual elements ever show, and no error dialogs. It is a silent shutdown when starting.</li>
  <li>Logging works, but there were no logged errors.</li>
  <li>He has uninstalled and reinstalled the .NET 4.0 Client Profile framework.</li>
  <li>He doesn't have any Visual Studio or other development tools mucking with stuff.</li>
  </ul>
  
  <p>I have spent a week or so eliminating theories and I'm becoming confused and desperate. Here are relevant details and things I have found:</p>
  
  <ul>
  <li>I am targeting x86 explicitly.</li>
  <li>The logging which failed to log any exception is set up to catch and log any unhandled exceptions and thread abort exceptions.</li>
  <li>Whatever is killing the application also prevents the final "shutting down" logging message in the program's basic entry point.</li>
  <li>I had read that certain icon (.ICO) file formats don't work in Windows XP. A far fetched theory, since this is Windows 7. This is the one and only case of ICO files in the project, so I was suspicious and switched it to PNG. No difference. I since figure that the image is failing merely because it is the first image loaded from a resource.</li>
  <li>I had read that the Form_Load event may swallow exceptions (and only when debugging). Also, InitializeComponent() is in the constructor, so the theory was shaky. Nonetheless, I wrapped the call to InitializeComponent() in a try/catch, but the catch and its associated logging never get called.</li>
  <li>I have seen posts about resource compilation problems between x86 and x64, but nothing relevant to runtime issues. (See <a href="http://blogs.msdn.com/b/visualstudio/archive/2010/06/19/resgen-exe-error-an-attempt-was-made-to-load-a-program-with-an-incorrect-format.aspx?PageIndex=3#comments" rel="nofollow">this post</a>)</li>
  <li>I assumed there must be something wrong unique with the program showing issues, so I made a WindowsFormsApplication1 test application with nothing more than a single image embedded in the associated resource file. This also fails to load in the same way. This test application was also targeting x86.</li>
  <li>It works fine on other x86 and x64 machines!</li>
  </ul>
  
  <p>What could possibly be going on his machine? Why is exception handling failing me? This problem is crazy!</p>
  
  <p><strong>Edit: More Details, and I'm still baffled!</strong><br></p>
  
  <ul>
  <li>I have since sent the test application (a single form with a single image on it) built as x86, x64, and "Any Cpu". The x64 and "Any Cpu" applications both work.</li>
  </ul>