简体   繁体   English

反序列化为 object 时出现“xmlns=''> 不是预期的”(在某些计算机上)

[英]"xmlns=''> was not expected" while deserializing to object (on some computers)

I am trying to deserialize XML.我正在尝试反序列化 XML。 I have no problems on my system either in dev env.我的系统在开发环境中也没有问题。 or runtime.或运行时。 My QA analyst has no problems, either.我的 QA 分析师也没有问题。 However, at the client site, we are getting the following error:但是,在客户端站点,我们收到以下错误:

There is an error in the XML document. XML 文档中存在错误。 System.InvalidOperationException: was not expected. System.InvalidOperationException:不是预期的。 at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReaderCrashEntity.Read74_CrashEntity() at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, String encodingStyle, XmlDeserializationEvents events) at Utility.XML.XMLUtility.DeserializeObject(String XML, Type ObjectType) at DirectoryFramework.ImportData() at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReaderCrashEntity.Read74_CrashEntity() at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, String encodingStyle, XmlDeserializationEvents events) at Utility.XML.XMLUtility.DeserializeObject(String XML, Type ObjectType) at DirectoryFramework.ImportData()

What could be causing this on the client site but not in dev/qa environment?是什么导致了客户端站点上的这种情况,但在 dev/qa 环境中却没有?

The source XML (small snippet):来源 XML(小片段):

<CitationEntity>
  <CitationNumber>E00C000006</CitationNumber>
  <Agency>123456789</Agency>
  <CaseNumber>1234456</CaseNumber>
</CitationEntity>

Deserialization method:反序列化方法:

Type entListType = typeof(List<>).MakeGenericType(entType);
object entities = null;
try
{
    entities = XMLUtility.DeserializeObject(outputXml, entListType);
}
catch (Exception ex)
{...}


public static Object DeserializeObject(String XML, Type ObjectType)
{
    Object retval = null;
    XmlSerializer serializer = new XmlSerializer(ObjectType);
    XmlDocument doc = new XmlDocument();
    doc.LoadXml(XML);
    XmlNode node = doc.DocumentElement;
    XmlReader readnode = new XmlNodeReader(node);
    retval = serializer.Deserialize(readnode);

    return retval;
}

Target class snippet:目标 class 片段:

[DataContract, Serializable]
[ModuleCode("TC")]
[InvolvementDate("CitationDate")]
[MFRStatusHistoryModuleCode("TC")]
public partial class CitationEntity : Entities.baseEntity, INameEntity
{
    [DataMember]
    [DefaultValue("")]
    public string Agency
    {
        get { return _Agency; }
        set
        {
            if (value != _Agency)
            {
                _Agency = value;
                OnPropertyChanged("Agency");
            }
        }
    }
    string _Agency;

    [DataMember]
    [DefaultValue("")]
    public string CaseNumber
    {
        get { return _CaseNumber; }
        set
        {
            if (value != _CaseNumber)
            {
                _CaseNumber = value;
                OnPropertyChanged("CaseNumber");
            }
        }
    }
    string _CaseNumber;

    [DataMember]
    [DefaultValue("")]
    public string CitationNumber
    {
        get { return _CitationNumber; }
        set
        {
            if (value != _CitationNumber)
            {
                _CitationNumber = value;
                OnPropertyChanged("CitationNumber");
            }
        }
    }
    string _CitationNumber;
}

I had .net Framework 4.7 installed on my computer and the client computer had 4.0 or so.我的计算机上安装了 .net Framework 4.7,而客户端计算机安装了 4.0 左右。 I thought that might be the issue.我认为这可能是问题所在。 We updated the client computer to 4.8 and it did not make a difference.我们将客户端计算机更新到 4.8,但并没有什么不同。 I updated to 4.8 and it still works as it should.我更新到 4.8,它仍然可以正常工作。

Sorry for the false alarm on this.很抱歉在此误报。 It has come to my attention that the target entity was incorrectly chosen as part of the installation of the product.我注意到目标实体被错误地选择为产品安装的一部分。 After I went over the installation configuration with the installer line by line, I noticed that the entity was for Crash, not Incident.在我使用安装程序逐行检查安装配置后,我注意到该实体是用于 Crash,而不是 Incident。 Once the correct entity was set, the deserialization worked like a charm.一旦设置了正确的实体,反序列化就像一个魅力。

Lesson learned...Don't assume that someone else installed the product correctly when there is an unexpected error.经验教训...当出现意外错误时,不要假设其他人正确安装了产品。

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

相关问题 将 Xml 反序列化为对象时出错 - 不需要 xmlns=&#39;&#39; - Error Deserializing Xml to Object - xmlns='' was not expected 将 Xml 反序列化为列表<T> - xmlns=&#39;&#39; 不是预期的 - Deserializing Xml to List<T> - xmlns='' was not expected {”<user xmlns=''> 不是预期的。} 反序列化 Twitter XML - {"<user xmlns=''> was not expected.} Deserializing Twitter XML 反序列化嵌套类时,不期望xmlns =&#39;&#39; - xmlns='' was not expected when deserializing nested classes 将Xml反序列化为对象时出错-{ <string xmlns='http://tempuri.org/'> 没想到。} - Error Deserializing Xml to Object - {<string xmlns='http://tempuri.org/'> was not expected.} xmlns=&#39;&#39;&gt; 不是预期的。 - DeserializeXml to object 时 XML 文档 (2, 2) 中存在错误 - xmlns=''> was not expected. - There is an error in XML document (2, 2) while DeserializeXml to object 反序列化派生类时,XmlSerializer异常( <Derived xmlns=''> 没想到) - XmlSerializer exception when deserializing derived class (<Derived xmlns=''> was not expected) 使用XML序列化反序列化数组时不期望元素 - Element was not expected While Deserializing an Array with XML Serialization 反序列化Json Object时预期结果不正确? - When Deserializing Json Object expected result is not correct? C#从xml反序列化到对象( <result xmlns=''> 没想到。) - C# Deserilize from xml to object (<result xmlns=''> was not expected.)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM