Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
RavenDB:XmlNodeConverter仅支持反序列化XmlDocuments_Xml_Json_Serialization_Ravendb - Fatal编程技术网

RavenDB:XmlNodeConverter仅支持反序列化XmlDocuments

RavenDB:XmlNodeConverter仅支持反序列化XmlDocuments,xml,json,serialization,ravendb,Xml,Json,Serialization,Ravendb,我无法从RavenDb反序列化XmlElement对象。我得到一个错误:XmlNodeConverter只支持反序列化XmlDocuments FooEventType类的代码是由Svcutil工具从wsdl和xsd文件生成的 [System.CodeDom.Compiler.GeneratedCodeAttribute("svcutil", "3.0.4506.2152")] [System.SerializableAttribute()] [System.Diagnostics.Debugg

我无法从RavenDb反序列化XmlElement对象。我得到一个错误:XmlNodeConverter只支持反序列化XmlDocuments

FooEventType类的代码是由Svcutil工具从wsdl和xsd文件生成的

[System.CodeDom.Compiler.GeneratedCodeAttribute("svcutil", "3.0.4506.2152")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace = "urn:eglobal:eis:xsd:1")]
public partial class FooEventType 
{
    private Foo[] fooListField;

    private System.Xml.XmlElement[] anyField;

    [System.Xml.Serialization.XmlArrayAttribute(Form = System.Xml.Schema.XmlSchemaForm.Unqualified, Order = 0)]
    [System.Xml.Serialization.XmlArrayItemAttribute("foo", Form = System.Xml.Schema.XmlSchemaForm.Unqualified, IsNullable = false)]
    public Foo[] fooList
    {
        get
        {
            return this.fooListField;
        }
        set
        {
            this.fooListField = value;
        }
    }

    /// <remarks/>
    [System.Xml.Serialization.XmlAnyElementAttribute(Order = 1)]
    public System.Xml.XmlElement[] Any
    {
        get
        {
            return this.anyField;
        }
        set
        {
            this.anyField = value;
        }
    }

}
在数据库中查询期间反序列化时的异常详细信息:

{
  "fooList": [
    {
      "Value": "test1"
    },
    {
      "Value": "test2"
    }
  ],
  "Any": [
    {
      "testOfProp": {
        "#whitespace": [
          "\n",
          "\n"
        ],
        "testOfValue": "XYZ"
      }
    }
  ]
}
System.InvalidOperationException was unhandled by user code
  HResult=-2146233079
  Message=Could not convert document FooEventTypes/8961 to entity of type EWcfService.FooEventType
  Source=Raven.Client.Lightweight
  StackTrace:
       at Raven.Client.Document.InMemoryDocumentSessionOperations.ConvertToEntity(Type entityType, String id, RavenJObject documentFound, RavenJObject metadata)
       at Raven.Client.Document.InMemoryDocumentSessionOperations.TrackEntity(Type entityType, String key, RavenJObject document, RavenJObject metadata, Boolean noTracking)
       at Raven.Client.Document.InMemoryDocumentSessionOperations.TrackEntity[T](String key, RavenJObject document, RavenJObject metadata, Boolean noTracking)
       at Raven.Client.Document.SessionOperations.QueryOperation.Deserialize[T](RavenJObject result)
       at System.Linq.Enumerable.WhereSelectListIterator`2.MoveNext()
       at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
       at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
       at Raven.Client.Document.SessionOperations.QueryOperation.Complete[T]()
       at Raven.Client.Document.AbstractDocumentQuery`2.GetEnumerator()
       at Raven.Client.Linq.RavenQueryInspector`1.GetEnumerator()
       at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
       at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
       at Epcis11WcfService.RavenDb.RavenDbEpcis.poll(pollRequest request) in d:\Activite\PROJ\DEV\Main\ESolution2\ESolution2\E11WcfService\RavenDb\RavenDbE.cs:line 99
       at E11WcfService.Query.poll(pollRequest request) in d:\Activite\PROJ\DEV\Main\ESolution2\ESolution2\E11WcfService\Query.svc.cs:line 47
       at SyncInvokepoll(Object , Object[] , Object[] )
       at System.ServiceModel.Dispatcher.SyncMethodInvoker.Invoke(Object instance, Object[] inputs, Object[]& outputs)
       at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc& rpc)
  InnerException: Raven.Imports.Newtonsoft.Json.JsonSerializationException
       HResult=-2146233088
       Message=Could not read value for property: Any
       Source=Raven.Abstractions
       StackTrace:
            at Raven.Imports.Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateObject(Object newObject, JsonReader reader, JsonObjectContract contract, JsonProperty member, String id)
            at Raven.Imports.Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
            at Raven.Imports.Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
            at Raven.Imports.Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent)
            at Raven.Imports.Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType)
            at Raven.Imports.Newtonsoft.Json.JsonSerializer.Deserialize(JsonReader reader, Type objectType)
            at Raven.Client.Connection.DocumentConventionJsonExtensions.Deserialize(RavenJObject self, Type type, DocumentConvention convention)
            at Raven.Client.Document.InMemoryDocumentSessionOperations.ConvertToEntity(Type entityType, String id, RavenJObject documentFound, RavenJObject metadata)
       InnerException: Raven.Imports.Newtonsoft.Json.JsonSerializationException
            HResult=-2146233088
            Message=XmlNodeConverter only supports deserializing XmlDocuments
            Source=Raven.Abstractions
            StackTrace:
                 at Raven.Imports.Newtonsoft.Json.Converters.XmlNodeConverter.ReadJson(JsonReader reader, Type objectType, Object existingValue, JsonSerializer serializer)
                 at Raven.Imports.Newtonsoft.Json.Serialization.JsonSerializerInternalReader.DeserializeConvertable(JsonConverter converter, JsonReader reader, Type objectType, Object existingValue)
                 at Raven.Imports.Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateList(IWrappedCollection wrappedList, JsonReader reader, JsonArrayContract contract, JsonProperty containerProperty, String id)
                 at Raven.Imports.Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateList(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, Object existingValue, String id)
                 at Raven.Imports.Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
                 at Raven.Imports.Newtonsoft.Json.Serialization.JsonSerializerInternalReader.SetPropertyValue(JsonProperty property, JsonConverter propertyConverter, JsonContainerContract containerContract, JsonProperty containerProperty, JsonReader reader, Object target)
                 at Raven.Imports.Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateObject(Object newObject, JsonReader reader, JsonObjectContract contract, JsonProperty member, String id)
            InnerException: 

我找到了这个解决办法。由于getter/setter,我在序列化时将XmlElement[]转换为XmlDocument[],并使用[XmlIgnore]和[JsonIgnore]属性。 但如果你有另一个解决方案,我仍然感兴趣

[System.CodeDom.Compiler.GeneratedCodeAttribute("svcutil", "3.0.4506.2152")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace = "urn:eglobal:eis:xsd:1")]
public partial class FooEventType 
{
    private Foo[] fooListField;

    private System.Xml.XmlDocument[] anyField;

    [System.Xml.Serialization.XmlArrayAttribute(Form = System.Xml.Schema.XmlSchemaForm.Unqualified, Order = 0)]
    [System.Xml.Serialization.XmlArrayItemAttribute("foo", Form = System.Xml.Schema.XmlSchemaForm.Unqualified, IsNullable = false)]
    public Foo[] fooList
    {
        get
        {
            return this.fooListField;
        }
        set
        {
            this.fooListField = value;
        }
    }

    /// <remarks/>
    [System.Xml.Serialization.XmlAnyElementAttribute(Order = 1)]
    [JsonIgnore]
    public XmlElement[] Any
    {
        get
        {
            return this.anyField.Select(x => x.DocumentElement).ToArray();
        }
        set
        {
            if (value != null)
            {
                this.anyField = new XmlDocument[value.Count()];
                for (int i = 0; i < value.Count(); i++)
                {
                    this.anyField[i] = new XmlDocument();
                    this.anyField[i].LoadXml(value[i].OuterXml);
                }
            }


        }
    }

    [System.Xml.Serialization.XmlIgnore]
    [JsonProperty(PropertyName = "Any")]
    public System.Xml.XmlDocument[] Any_ForRavenJsonSerialization
    {
        get
        {
            return this.anyField;
        }

        set
        {
            this.anyField = value;
        }
    }

}