title: urlmon.dll FindMimeFromData() works perfectly on 64bit desktop/console but generates errors on ASP.NET
body: <p>I am creating a library of utilities to be used both in desktop environment in a web environment.</p>
  
  <p>It contains several features that I believe are often repeated in my applications, including utility to get the mime type of a file by its content (not the extension).</p>
  
  <p>The files that I'll have to check are the most common (jpg, png, pdf, txt) so I chose to use the external method <code>FindMimeFromData</code> (link above)</p>
  
  <p><a href="https://stackoverflow.com/questions/58510/using-net-how-can-you-find-the-mime-type-of-a-file-based-on-the-file-signature/58570#58570">Using .NET, how can you find the mime type of a file based on the file signature not the extension</a></p>
  
  <p>The method works well, except for the two incorrect mime type of JPG (<code>image/pjpg</code>) and PNG (<code>image/x-png</code>), easily solved by doing a check before the return statement.</p>
  
  <p>The library is compiled for the platform AnyCPU, because it must be installed on servers/clients in both 32 and 64 bits.</p>
  
  <p>At the time of testing on desktop environment all working properly for both applications compiled for x86 and x64.</p>
  
  <p>at the time of testing an ASP.NET application (an empty site with an http handler for test) occurs an error of type HRESULT, and the debugger tells me that it can not provide further information.</p>
  
  <p>After a few test configuration, including changing the identity of the pool to Local System (with no result), I have identified the problem:</p>
  
  <p>the pool should allow 32-bit applications (see image above).</p>
  
  <p><img src="https://i.stack.imgur.com/YLSew.png" alt="IisAllow32BitApplication"></p>
  
  <p>Why?</p>
  
  <p>It should not load the dll <code>urlmon.dll</code> of the 64bit system where we are now?</p>
  
  <p>This is a big problem, because the <code>FindMimeFromData</code> method can be invoked by everywhere into this library:</p>
  
  <p>the result is that an invocation of this method by another utility method may throw this exception and making it difficult to trace the problem also through debugging.</p>
  
  <p>Any ideas/experience ?</p>
  
  <p><strong>Operating Systems used for testing</strong></p>
  
  <p>Desktop:</p>
  
  <ol>
  <li>Windows 8 x64 - <em>works</em></li>
  <li>Windows 7 x64 - <em>works</em></li>
  <li>Windows Server 2008 Standard R2 x64 - <em>works</em></li>
  <li>Windows Server 2008 Standard x86 - <em>works</em></li>
  <li>Windows Server 2003 Standard x86 - <em>works</em></li>
  <li>Windows XP Professional SP3 - <em>works</em></li>
  </ol>
  
  <p>Web:</p>
  
  <ol>
  <li>Windows 8 x64 - <em>first error found, works only with 32bit application enabled</em></li>
  <li>Windows Server 2008 Standard R2 x64 - <em>error confirmed, works only with 32bit application enabled</em></li>
  <li>Windows Server 2008 Standard x86 - <em>works</em></li>
  </ol>
  
  <p><strong>EDIT 2 (question solved)</strong></p>
  
  <p>Solved by <a href="https://stackoverflow.com/users/1768303/noseratio">Noseratio</a>:</p>
  
  <p>The correct type of parameters <code>ppwzMimeOut</code> and <code>pBC</code> must be <code>System.IntPtr</code> instead of <code>System.UInt32</code>.</p>
  
  <p>I know that <code>System.UInt32</code> causes problems into full 64bit web-apps, but i don't know why.</p>
  
  <p>If someone know the reason of these problems, can explain it better in a comment?</p>
  
  <p>Thanks in advance</p>