1

I have a program that serializes its settings to XML using the XmlSerializer class. It works fine on all Windows 7 machines, but fails on Windows XP SP3 machines with the following error message:

System.InvalidOperationException: Unable to generate a temporary class (result=1).
error CS0012: The type 'System.Windows.UIElement' is defined in an assembly that is not referenced. You must add a reference to assembly 'PresentationCore, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.
error CS0012: The type 'System.Windows.IInputElement' is defined in an assembly that is not referenced. You must add a reference to assembly 'PresentationCore, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.
error CS0012: The type 'System.Windows.Markup.IQueryAmbient' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Xaml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.

   at System.Xml.Serialization.Compiler.Compile(Assembly parent, String ns, XmlSerializerCompilerParameters xmlParameters, Evidence evidence)
   at System.Xml.Serialization.TempAssembly.GenerateAssembly(XmlMapping[] xmlMappings, Type[] types, String defaultNamespace, Evidence evidence, XmlSerializerCompilerParameters parameters, Assembly assembly, Hashtable assemblies)
   at System.Xml.Serialization.XmlSerializer.GenerateTempAssembly(XmlMapping xmlMapping, Type type, String defaultNamespace)
   at System.Xml.Serialization.XmlSerializer..ctor(Type type, String defaultNamespace)

PresentationCore and System.Xaml are present in the reference list of the project, and after searching an forums I set Generate serialization assembly from Auto to On, but with no result. Any idea what could go wrong on Windows XP?

PS: I use .net 4, and the problem appears on Windows XP SP3 machines with .net framework 4 (v4.0.30319) and the latest updates.

Robot Mess
  • 949
  • 1
  • 7
  • 31

2 Answers2

0

This could be related to a bug Microsoft won't fix. See this SO post for more information:

SO: XmlSerializer is throwing InvalidOperationException when using the generic type constraint where

Unfortunately the link to the original Microsoft post is down, so I can't say for sure if this applies to your case.

Community
  • 1
  • 1
Physikbuddha
  • 1,652
  • 1
  • 15
  • 30
  • I would love to be able to use DataContractSerializer, but it does not support XML attributes, so it's not an option – Robot Mess May 07 '15 at 15:23
  • I looked it up in more detail, it does not apply in my case since I am not serializing any generic classes. – Robot Mess May 08 '15 at 06:22
0

You should be able to fix it by building and deploying the serialization assembly (*.XmlSerializers.dll).

This is just a workaround really but completely avoids dynamically compiling the serializers when they are first used.

Community
  • 1
  • 1
Peter Wishart
  • 11,600
  • 1
  • 26
  • 45
  • I am trying the solutions posted there, but since I have multiple DLLs, SGEN seems to get confused and spits compile time errors: Unable to generate a temporary class (result=1) The type 'XamlGeneratedNamespace.GeneratedInternalTypeHelper' exists in both 'lib1.dll' and 'lib2.dll' – Robot Mess May 07 '15 at 14:59
  • AFAIK if they can be generated at runtime, they can be generated at compile time. You could try the [docs for sgen](https://msdn.microsoft.com/en-us/library/bk3w6240%28v=vs.110%29.aspx?f=255&MSPPError=-2147217396), maybe run SGEN via the VS command prompt and tweak options until it works? – Peter Wishart May 07 '15 at 15:16
  • yup, I am reading the docs right now, I didn't use SGEN before so I guess problems are to be expected – Robot Mess May 07 '15 at 15:21