Take the 2-minute tour ×

I'm working with VS2008 and VS2010 for different projects simultaneously. Recently I tried to generate the serialization assemblies for the Entities Project and was unable to generate the same via visual studio 2010. This throws up the below error:

An attempt was made to load an assembly with an incorrect format: X:\Dev\Proj\X.Entities\bin\Debug\X.entities.dll.

This is be post build event I have setup for the Entities project

"$(FrameworkSDKDir)\Bin\sgen" /nologo /force $(TargetFileName)
copy "$(TargetDir)X.Entities.Serializer.dll" "$(SolutionDir)\X.Site\Bin"

I'm able to generate the Serializer dll from the VS 2010 command line. For the VS2008 projects; the lines are working fine. However, the errors are on the VS2010 projects!

Is there a different FrameworkSDKDir variable for VS2010? if not, how do I modify it to work with both VS2010 and VS2008 projects?

BTW, I use win 2008 Server 32-bit OS, IIS 7 for the development.

share|improve this question
There are 4 versions of sgen.exe in VS2010. Combinations of 32-bit vs 64-bit and CLR 2 vs CLR 4. I'm guessing you are getting the .NET 4 version and trying to load it in a project that targets CLR 2. –  Hans Passant Apr 20 '12 at 12:07
@HansPassant: All the projects are set to 4.0 Framework, hence I don't think it is trying to load CLR 2. Even if it is pointing to, how can I change that? –  Kay Apr 20 '12 at 12:16
First you must identify the problem, then you can think about fixing it. Use ildasm.exe to verify your assumptions, it shows the expected CLR version in the manifest. –  Hans Passant Apr 20 '12 at 12:20

1 Answer 1

up vote 3 down vote accepted

sgen that you are pointing to is for CLR 2.0. Ideally it will be located at C:\Program Files\Microsoft SDKs\Windows\v7.0A\bin.

There is a 4.0 version of sgen under "C:\Program Files\Microsoft SDKs\Windows\v7.0A\bin\NETFX 4.0 Tools" which resolves the issue.

Your post build command should start like this:

"$(FrameworkSDKDir)\bin\NETFX 4.0 Tools\sgen"
share|improve this answer

Your Answer


