SGEN doesn't work after upgrading from VS2008 to VS2010

守給你的承諾、 提交于 2019-11-28 07:57:13

问题


I just recently upgraded a VS2008/.NET 3.5 SP1 project to VS2010 and .NET 4. I have a post-build event which calls SGEN to generate the XmlSerializers assembly.

Whenever I try to run it I get the following error.

"C:\Program Files\Microsoft SDKs\Windows\v7.0A\bin\sgen.exe" /debug /force /verbose /c:"platform:x86" "C:\path\to\SomeAssembly.dll"
Microsoft (R) Xml Serialization support utility
[Microsoft (R) .NET Framework, Version 2.0.50727.3038]
Copyright (C) Microsoft Corporation. All rights reserved.
Error: An attempt was made to load an assembly with an incorrect format: c:\path\to\someassembly.dll.
  - Could not load file or assembly 'file:///c:\path\to\someassembly.dll'
or one of its dependencies. This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded.

If you would like more help, please type "sgen /?".

I get the same error running SGEN from the command line, but I can't figure out what the problem is. Any ideas?


回答1:


Yes, there are two versions of sgen.exe available, one for CLR v2 assemblies, the other for CLR v4 assemblies. It bombs because you ask the v2 version of sgen.exe to process a v4 assembly.

Check how your project gets sgen.exe started. If it is a post-build event then you'll have to tweak the path to sgen.exe. I don't see a macro or environment variable to get it right automatically, bit of an oversight.




回答2:


Seems like that second line of output from SGEN is important:

[Microsoft (R) .NET Framework, Version 2.0.50727.3038]

I found another version of SGEN which seems to work at C:\Program Files\Microsoft SDKs\Windows\v7.0A\bin\NETFX 4.0 Tools\sgen.exe. It outputs this when you run it:

[Microsoft (R) .NET Framework, Version 4.0.30319.1]

I'm not sure why both are included in the Windows 7 SDK...



来源:https://stackoverflow.com/questions/2746372/sgen-doesnt-work-after-upgrading-from-vs2008-to-vs2010

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!