After copying a web site to a 64bit server with IIS 7, I was getting the following error message:
Could not load file or assembly ‘PresentationCore’ or one of its dependencies. An attempt was made to load a program with an incorrect format.
although everything was working fine when running the site on my machine (32bit WinXP with IIS 6).
I did some research, and some people suggested to turn on “Enable 32-bit Applications” in my web site application pool advanced property. However, I was not satisfied with that answer. All my DLL’s were supposed to be compatible with 64-bit, so I did not see why I should turn on that setting.
One thing I have to mention here is that I was using MSBUILD to compile my web application on the server with a line like:
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Msbuild.exe Extranet.csproj /t:Build
After much researching, I noticed that each time the project was compiled with the line above, two files were added to the bin directory of my web application:
- PresentationCore.dll
- System.Printing.dll
I never added these files to the project, and I did not reference them either. They were added automatically by MSBuild every time I would compile. This was the culprit. After doing more investigation, I discovered that if I compiled with the proper version of MsBuild, this did not happen anymore. So I changed my compiling line above for this one and everything was fine or almost:
c:\Windows\Microsoft.NET\Framework64\v3.5\MSBuild.exe Extranet.csproj /t:Build
Notice the changes: Framework -> Framework64 and v2.0.50727 -> v3.5.
Earlier, I said that using that version of MsBuild solves everything or almost because I then got some compilation errors, but they are easy to fix. I did not have Visual Studio installed on the server, so two sets of files were missing for the compilation to succede. The compiler was complaining about WebAppications.targets and WebProfileBuilder.targets. If this happens, you can simply copy the follwoing folders from a machine where you have Visual Studio installed to your server:
- C:\Program Files\MSBuild\Microsoft\VisualStudio\v9.0\WebAppications
- C:\Program Files\MSBuild\WebProfileBuilder
After doing so, everything complied fine, and I did not have any complaint about PresentationCore anymore.
Hope this helps!