C#XmlSerialization在Windows XP上失败

时间:2015-05-07 14:13:38

标签: c# .net xml-serialization windows-xp-sp3

我有一个程序,使用XmlSerializer类将其设置序列化为XML。它适用于所有Windows 7计算机,但在Windows XP SP3计算机上失败,并显示以下错误消息:

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和System.Xaml存在于项目的参考列表中,在搜索论坛后,我将生成序列化程序集从Auto设置为On,但没有结果。 知道Windows XP上可能出现什么问题吗?

PS:我使用.net 4,问题出现在带有.net framework 4(v4.0.30319)和最新更新的Windows XP SP3计算机上。

2 个答案:

答案 0 :(得分:0)

这可能与微软未能修复的错误有关。有关更多信息,请参阅此SO帖子:

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

很遗憾,原始Microsoft帖子的链接已关闭,因此我无法确定这是否适用于您的案例。

答案 1 :(得分:0)

您应该能够通过building修复它并部署序列化程序集(* .XmlSerializers.dll)。

这只是一种解决方法,但完全避免在首次使用时动态编译序列化程序。