Running sgen.exe on a .NET 4.5 assembly?

1.3k views Asked by At

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"

0

There are 0 answers