0

I used to run sgen.exe from C:\Program Files\Microsoft SDKs\Windows\v7.1\Bin\sgen.exe and targeted a .NET 4 assembly and it built just fine. After upgrading the project to .NET 4.5, it fails with this error:

Microsoft (R) Xml Serialization support utility
[Microsoft (R) .NET Framework, Version 2.0.50727.3038]
Copyright (C) Microsoft Corporation. All rights reserved.
sgen.exe : Error: Unable to generate a temporary class (result=1).
error CS0012: The type 'System.Object' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.
error CS0012: The type 'System.ComponentModel.INotifyPropertyChanged' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.ObjectModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.

I figured I would need an updated sgen.exe for the new framework, so I tried C:\Program Files (x86)\Microsoft SDKs\Windows\v8.1A\bin\NETFX 4.5.1 Tools and C:\Program Files (x86)\Microsoft SDKs\Windows\v8.0A\bin\NETFX 4.0 Tools but those failed as well:

Microsoft (R) Xml Serialization support utility
[Microsoft (R) .NET Framework, Version 4.0.30319.33440]
Copyright (C) Microsoft Corporation. All rights reserved.
Error: Unable to generate a temporary class (result=1).
error CS0012: The type 'System.Object' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.
error CS0012: The type 'System.ComponentModel.INotifyPropertyChanged' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.ObjectModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.

Is it possible to use sgen.exe on a .net 4.5 assembly?

(edit) Using command line:

PS C:\Program Files (x86)\Microsoft SDKs\Windows\v8.1a\bin\NETFX 4.5.1 Tools\x64> . .\sgen /f /a:"D:\MyProject\bin\x64\Debug\MyProgram.exe"

RandomEngy
  • 14,931
  • 5
  • 70
  • 113
  • First one fails because you use the wrong sgen version. Second one fails because you use the [wrong reference assemblies](http://stackoverflow.com/a/13750130/17034). Not documenting the command line you use to start sgen.exe makes it hard to help you. – Hans Passant Jun 14 '15 at 07:35
  • @HansPassant Okay I've added the command line I'm trying. Though /targetplatform doesn't exist on sgen.exe and adding `/reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5"` or `/reference:"v4,C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5"` doesn't seem to help. I did try running this on a simple DLL though and it worked! So maybe it doesn't like my executable? – RandomEngy Jun 14 '15 at 15:22

0 Answers0