When I compile my SharePoint 2007 solution on a 64-bit machine in Release mode and the platform set to AnyCPU or x86 I get the following error:
An attempt was made to load an assembly with an incorrect format: C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\ISAPI\Microsoft.Office.Server.Search.dll.
When I use .Net Reflector on Microsoft.Office.Server.Search.dll it says the platform is set to x64. So I change my settings to Release mode and the platform to x64 and get the same error.
The strange thing is when I change Release to debug, It complies. Can anyone explain this?
I would prefer compiling with the settings Release/AnyCPU if its possible. Can anyone give me a push in the right direction?
Friday, October 22, 2010 5:58 PM
I think Office is in 32 bit mode. I didn't know the compiler would catch the error I thought it would only be apparent at run time. Put the BUILD format to 32Bit and you should be OK.
ReneeSunday, October 24, 2010 5:02 PM
This error is quite often seen in this forum. Please make sure if the dll is 32bit or 64bit and take a look at here to decide the correct combination.
Please mark the right answer at the right time.
SamFriday, November 05, 2010 9:52 AM
Thank you for trying to help. However, this does not solve my problem. I am still unable to compile the solution. I have not yet gotten to running my dll. No mater the build type (32bit, 64bit, AnyCpu) in Release mode, I am unable to compile the solution and receive the error marked above. MOSS 2007 64bit is installed on windows server 2008 R2 64bit. I am trying to compile with visual studio 2008 on the same machine. The MOSS dll in question is a 64bit dll.
The solution compiles and runs when the mode is set to debug and AnyCpu.
Thanks again.Friday, November 05, 2010 12:55 PM
I'm having the exact same problem i.e. trying to compile a DLL that references
c:\program files\common files\microsoft shared\web server extensions\14\ISAPI\Microsoft.Office.Server.Search.dll
in release mode on a 64 bit platform in VS2010 gives the error
"SGEN: error: An attempt was made to load an assembly with an incorrect format"
Did you ever find out the cause or get a workaround? It compiles ok in debug just not in release.
GrahamMonday, April 18, 2011 9:43 AM
Managed to work around this problem.
Looks like it's due to Microsoft.Office.Server.Search.dll not being a MSIL dll but instead being specifically compiled to run on AMD64. I guess this means that SGEN is unable to reflect on it and build Serialization classes.
So the work around was to set "Geneate Serialization Assembly" to "Off" on the project properties for the release build configuration.
Monday, April 18, 2011 11:35 AM
- Proposed as answer by MOSSPro Monday, April 18, 2011 11:35 AM