Problem with corflags on interop library after VS upgrade
I converted my visual studio solution from 2008 to 2010. A project has a reference to ShDocVw. When I run the program I get a BadImageFormatException. Googling led me to check the interop library with corflags:
corflags Interop.ShDocVw.dll
Version : v2.0.50727
CLR Header: 2.5
PE : PE32
CorFlags : 3
ILONLY : 1
32BIT : 1
Signed : 0
Sure enough, the 32BIT flag is set so my application built as Any CPU on 64-bit machine cannot load开发者_如何转开发 this library. If I run corflags /32BIT- I can turn off the 32BIT flag and everything works just fine. The question is, why is this Interop library generated with that flag set? I didn't have that problem with VS2008, this only started happening after the upgrade.
More importantly, how can I fix it so that I don't have to run corflags to turn the bit off? I assume that it is probably due to some MSBuild-fu that I don't understand very well. I haven't been able to spot anything, anyway.
The problem is that after the upgrade the <PlatformTarget> tag is not set in certain <PropertyGroups> in the C# project files and it apparently defaults to x86. So, to fix this go to the project Properties -> Build tab and set Platform Target to something other than AnyCPU, save it. Now set it back to AnyCPU and save it. The <PlatformTarget> will be written to the project with the value of AnyCPU and all is well.
Here is where I found the answer.
精彩评论