Archived Forum Post

Index of archived forum posts

Question:

SGEN Fails with Incorrect Format?

Nov 01 '12 at 14:53

I can not get the x64 DLL to build as Release.

I get: "An attempt was made to load an assembly with an incorrect format: C:WindowsMicrosoft.NETassemblyGAC_64ChilkatDotNet4.dll." - SGEN

I normally build it simply from the Program Files directory. As a last resort I put it into the GAC 64 after reading your online articles.

It runs fine in debug, and I've used the 32-bit without issues for years. I have been migrating my app to 64-bit the last few days, and this is all I have left.

I have tried to build Release using both AnyCPU and x64. I get the same SGEN error either way.

Any ideas?


Answer

This problem only applies to SGEN. For the more general "incorrect format" problem, see this: .NET Incorrect Format Problem.

After reading through countless StackOverflow documents, I ran across someone that mentioned "make sure it's using the 64 bit SGEN". It was not, even though everything was set to x64. Actually nothing I tried got it to call the correct X64 SGEN so I simply deleted the x86 SGEN folder and copied all the contents of x64 folder into it and it worked.

The DLL is load correctly when installed now the SGEN worked.


Answer

I have some additional notes for you on this issue, too. It's not SGEN related, but it was another issue I had once I got the 64-bit app deployed to a test machine. The app kept crashing when loading your DLL.

Your DLL is dependent on the VC msvcr100.dll and with my 32 bit app, I had stuck the 32-bit DLL in the directory with your DLL for deployment. It was a way of always insuring your DLL could access it. I had not updated the installer to NOT deploy that 32-bit VC DLL and it was keeping your DLL from loading properly. Once I removed it and loaded the x64 VC runtime, it's working.

So, to recap, for SGEN errors, developers need to make sure that the 64-bit SGEN is running, not the 32-bit. With DLL load issues, make sure the 64-bit VC runtime is deployed. I have since updated the installer to run the MS runtime installer instead of "hardcoding" the DLL to the installer. I use Setup Factory, add the MS runtime as a Primer file and call it like this:

File.Run("wusa.exe", SessionVar.Expand("%TempLaunchFolder%\vcredist_x64.exe /q:a"), "", SW_SHOWNORMAL, true);

For 32-bit, they can use vcredist_x86.exe, of course.

I appreciate your tools. My company is quite dependent on them...