简体   繁体   English

Windows XP上的C#XmlSerialization失败

[英]C# XmlSerialization failing on Windows XP

I have a program that serializes its settings to XML using the XmlSerializer class. 我有一个程序使用XmlSerializer类将其设置序列化为XML。 It works fine on all Windows 7 machines, but fails on Windows XP SP3 machines with the following error message: 它在所有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 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. PresentationCore和System.Xaml存在于项目的参考列表中,并且在搜索了论坛之后,我将“生成序列化程序集”从“自动”设置为“开”,但没有结果。 Any idea what could go wrong on Windows XP? 知道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. PS:我使用.net 4,问题出现在具有.net Framework 4(v4.0.30319)和最新更新的Windows XP SP3计算机上。

This could be related to a bug Microsoft won't fix. 这可能与Microsoft无法修复的错误有关。 See this SO post for more information: 有关更多信息,请参见此SO帖子:

SO: XmlSerializer is throwing InvalidOperationException when using the generic type constraint where SO:使用通用类型约束时,XmlSerializer引发InvalidOperationException,其中

Unfortunately the link to the original Microsoft post is down, so I can't say for sure if this applies to your case. 不幸的是,原始Microsoft帖子的链接已关闭,因此我无法确定这是否适用于您的情况。

You should be able to fix it by building and deploying the serialization assembly (*.XmlSerializers.dll). 您应该能够通过构建和部署序列化程序集(* .XmlSerializers.dll)进行修复。

This is just a workaround really but completely avoids dynamically compiling the serializers when they are first used. 确实,这只是一个解决方法,但是完全避免了在首次使用序列化程序时对其进行动态编译。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM