.NET 4 反序列化问题:非法调用保留方法

发布于 2024-10-03 17:26:56 字数 2701 浏览 2 评论 0原文

在某些(但不是全部)机器上,当我们尝试使用(用 C# 编写)System.Xml.Serialization.XmlSerializer.Deserialize(TextReader textReader) 反序列化某些 XML 时
我们得到了一种与安全相关的错误,如下面的错误消息和堆栈跟踪所述。该异常是由 .NET 在序列化/反序列化时生成的程序集引发的。 在下面的堆栈跟踪中,AggregateElement 派生自 Element。 我们在 .NET 3.5 上没有遇到任何问题,并且自从升级到 .NET 4 以来我们的代码也没有改变 有人对这是什么以及为什么有任何想法吗?

错误:从“Microsoft.Xml.Serialization.GenerateAssembly.XmlSerializationReaderSheet.Read72_Element()”非法调用保留方法“Microsoft.Xml.Serialization.GenerateAssembly.XmlSerializationReaderSheet.Read53_AggregateElement()”。

调用堆栈 Microsoft.Xml.Serialization.GenerateAssembly.XmlSerializationReaderSheet.Read53_AggregateElement(Boolean isNullable, Boolean checkType)

在 Microsoft.Xml.Serialization.GenerateAssembly.XmlSerializationReaderSheet.Read72_Element(Boolean isNullable, Boolean checkType)

在 Microsoft.Xml.Serialization.GenerateAssembly.XmlSerializationReaderSheet.Read74_Section(Boolean isNullable, Boolean checkType)

在 Microsoft.Xml.Serialization.GenerateAssembly.XmlSerializationReaderSheet.Read70_SubForm(Boolean isNullable, Boolean checkType)

在 Microsoft.Xml.Serialization.GenerateAssembly.XmlSerializationReaderSheet.Read72_Element(Boolean isNullable, Boolean checkType)

在 Microsoft.Xml.Serialization.GenerateAssembly.XmlSerializationReaderSheet.Read74_Section(Boolean isNullable, Boolean checkType)

在 Microsoft.Xml.Serialization.GenerateAssembly.XmlSerializationReaderSheet.Read70_SubForm(Boolean isNullable, Boolean checkType)

在 Microsoft.Xml.Serialization.GenerateAssembly.XmlSerializationReaderSheet.Read92_Sheet(Boolean isNullable, Boolean checkType)

在 Microsoft.Xml.Serialization.GenerateAssembly.XmlSerializationReaderSheet.Read93_Sheet()

在 System.RuntimeMethodHandle._InvokeMethodFast(IRuntimeMethodInfo 方法、对象目标、Object[] 参数、SignatureStruct& sig、MethodAttributes methodAttributes、RuntimeType typeOwner)

在 System.RuntimeMethodHandle.InvokeMethodFast(IRuntimeMethodInfo 方法、对象目标、Object[] 参数、签名 sig、MethodAttributes methodAttributes、RuntimeType typeOwner)

在System.Reflection.RuntimeMethodInfo.Invoke(对象obj,BindingFlags invokeAttr,Binder活页夹,Object[]参数,CultureInfo文化,布尔skipVisibilityChecks)

在System.Reflection.RuntimeMethodInfo.Invoke(对象obj,BindingFlags invokeAttr,Binder活页夹,Object[]参数,CultureInfo文化)

在 System.Xml.Serialization.TempAssembly.InvokeReader(XmlMapping 映射、XmlReader xmlReader、XmlDeserializationEvents 事件、字符串编码样式)

在System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader,字符串encodingStyle,XmlDeserializationEvents事件)

在 System.Xml.Serialization.XmlSerializer.Deserialize(TextReader textReader)

On some, but not all, machines when we try to deserialize some XML using (written in C#) System.Xml.Serialization.XmlSerializer.Deserialize(TextReader textReader)
we get a kind of security related error described in the error message and stack trace below. The exception is thrown by the assembly that gets generated by .NET when serializing/deserializing.
In the stack trace below, AggregateElement derives from Element.
We haven't had any problems with .NET 3.5 and our code hasn't changed since we've upgraded to .NET 4
Does anyone have any ideas on what and why this is?

Error: Illegal call to the reserved method 'Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReaderSheet.Read53_AggregateElement()' from 'Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReaderSheet.Read72_Element()'.

Call Stack Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReaderSheet.Read53_AggregateElement(Boolean isNullable, Boolean checkType)

at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReaderSheet.Read72_Element(Boolean isNullable, Boolean checkType)

at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReaderSheet.Read74_Section(Boolean isNullable, Boolean checkType)

at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReaderSheet.Read70_SubForm(Boolean isNullable, Boolean checkType)

at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReaderSheet.Read72_Element(Boolean isNullable, Boolean checkType)

at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReaderSheet.Read74_Section(Boolean isNullable, Boolean checkType)

at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReaderSheet.Read70_SubForm(Boolean isNullable, Boolean checkType)

at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReaderSheet.Read92_Sheet(Boolean isNullable, Boolean checkType)

at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReaderSheet.Read93_Sheet()

at System.RuntimeMethodHandle._InvokeMethodFast(IRuntimeMethodInfo method, Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeType typeOwner)

at System.RuntimeMethodHandle.InvokeMethodFast(IRuntimeMethodInfo method, Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeType typeOwner)

at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)

at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)

at System.Xml.Serialization.TempAssembly.InvokeReader(XmlMapping mapping, XmlReader xmlReader, XmlDeserializationEvents events, String encodingStyle)

at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, String encodingStyle, XmlDeserializationEvents events)

at System.Xml.Serialization.XmlSerializer.Deserialize(TextReader textReader)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文