C# 无法序列化成员<;x>;因为它是一个接口

C# 无法序列化成员<;x>;因为它是一个接口,c#,asp.net,deserialization,xml-serialization,neo4jclient,C#,Asp.net,Deserialization,Xml Serialization,Neo4jclient,后续问题来自 来自WebMethod的代码 return client.Cypher .Match("(person:Person)") .Where((Person person) => person.Email == username) .OptionalMatch("(person)-[:SPEAKS]-(language:Language)") .OptionalMatch("(person)-[:CURRENT_LO

后续问题来自

来自WebMethod的代码

return client.Cypher
        .Match("(person:Person)")
        .Where((Person person) => person.Email == username)
        .OptionalMatch("(person)-[:SPEAKS]-(language:Language)")
        .OptionalMatch("(person)-[:CURRENT_LOCATION]-(country:Country)"
        .Return((person, language, country) => new ProfileObject
        {
            Person = person.As<Person>(),
            Language = language.CollectAs<Language>(),
            Country = country.CollectAs<Country>()
        }).Results.ToList();
ProfileObject类中的新代码:

public class ProfileObject
{
    public Person Person { get; set; }
    public IEnumerable<Node<Language>> Language { get; set; }
    public IEnumerable<Node<Country>> Country { get; set; }
}
然后它就可以工作了(但是对于返回的每个Country对象,我显然会得到重复的Person条目)

有谁能给我一个解决这个问题的方法,而不需要我把所有的代码都撕下来重新开始

更新:

[InvalidOperationException:Neo4jClient.Node`1[Graph.Language]无法序列化,因为它没有无参数构造函数。]

[InvalidOperationException:无法序列化“System.Collections.Generic.List”类型的成员“Graph.ProfileObject.Language”
1[[Neo4jClient.Node
1[[Graph.Language,Graph,Version=1.0.0.0,Culture=neutral,PublicKeyToken=null]],Neo4jClient,Version=0.0.0.0,Culture=neutral,PublicKeyToken=null]],有关详细信息,请参阅内部异常。] System.Xml.Serialization.StructModel.CheckSupportedMember(TypeDesc TypeDesc,MemberInfo成员,Type类型)+5451673 System.Xml.Serialization.StructModel.CheckSupportedMember(TypeDesc TypeDesc,MemberInfo成员,Type类型)+69 System.Xml.Serialization.StructModel.GetPropertyModel(PropertyInfo PropertyInfo)+125 System.Xml.Serialization.StructModel.GetFieldModel(MemberInfo MemberInfo)+89 System.Xml.Serialization.XmlReflectionImporter.InitializeStructMembers(StructMapping映射、StructModel模型、布尔openModel、字符串类型名、递归限制器)+618 System.Xml.Serialization.XmlReflectionImporter.ImportStructLikeMapping(StructModel模型、字符串ns、布尔openModel、XmlAttributes a、递归限制器)+378 System.Xml.Serialization.XmlReflectionImporter.ImportTypeMapping(类型模型、字符串ns、ImportContext上下文、字符串数据类型、XmlAttributes a、布尔重复、布尔openModel、递归限制器)+1799

[InvalidOperationException:反映类型“Graph.ProfileObject”时出错。] System.Xml.Serialization.XmlReflectionImporter.ImportTypeMapping(类型模型、字符串ns、ImportContext上下文、字符串数据类型、XmlAttributes a、布尔重复、布尔openModel、递归限制器)+1917 System.Xml.Serialization.XmlReflectionImporter.CreateArrayElementsFromAttributes(ArrayMapping ArrayMapping、XmlArrayItemAttributes属性、类型arrayElementType、字符串ArrayElements、递归限制器)+263 System.Xml.Serialization.XmlReflectionImporter.ImportArrayLikeMapping(ArrayModel模型,字符串ns,递归限制器)+264 System.Xml.Serialization.XmlReflectionImporter.ImportAccessorMapping(MemberMapping访问器、FieldModel模型、XmlAttributes a、字符串ns、类型choiceIdentifierType、布尔rpc、布尔openModel、递归限制器)+5456308 System.Xml.Serialization.XmlReflectionImporter.ImportMemberMapping(XmlReflectionMember XmlReflectionMember,字符串ns,XmlReflectionMember[]xmlReflectionMembers,布尔rpc,布尔openModel,递归限制器)+852 System.Xml.Serialization.XmlReflectionImporter.ImportMembersMapping(XmlReflectionMember[]xmlReflectionMembers,字符串ns,布尔hasWrapperElement,布尔rpc,布尔openModel,递归限制器)+286

[InvalidOperationException:出现反映“MyResult”的错误。] System.Xml.Serialization.XmlReflectionImporter.ImportMembersMapping(XmlReflectionMember[]xmlReflectionMembers,字符串ns,布尔hasWrapperElement,布尔rpc,布尔openModel,递归限制器)+979 System.Xml.Serialization.XmlReflectionImporter.ImportMembersMapping(String elementName、String ns、XmlReflectionMember[]成员、Boolean hasWrapperElement、Boolean rpc、Boolean openModel、XmlMappingAccess)+133 System.Web.Services.Protocols.SoapReflector.ImportMembersMapping(XmlReflectionImporter xmlImporter,SoapReflectionImporter soapImporter,Boolean serviceDefaultIsEncoded,Boolean rpc,SoapBindingUse use,SoapParameterStyle paramStyle,String elementName,String elementNamespace,Boolean nsIsDefault,XmlReflectionMember[]成员,布尔验证,布尔openModel,字符串键,布尔写访问)+240 System.Web.Services.Protocols.SoapReflector.ReflectMethod(LogicalMethodInfo方法信息、布尔客户端、XmlReflectionImporter xmlImporter、SoapReflectionImporter soapImporter、字符串defaultNs)+2893

[InvalidOperationException:Method ProfileServices.My无法反映。] System.Web.Services.Protocols.SoapReflector.ReflectMethod(LogicalMethodInfo方法信息、布尔客户端、XmlReflectionImporter xmlImporter、SoapReflectionImporter soapImporter、字符串defaultNs)+6173 System.Web.Services.Description.SoapProtocolReflector.ReflectMethod()+137 System.Web.Services.Description.ProtocolReflector.ReflectBinding(ReflectedBinding ReflectedBinding)+1776 System.Web.Services.Description.ProtocolReflector.Reflect()+641 System.Web.Services.Description.ServiceDescriptionReflector.ReflectionInternal(ProtocolReflector[]reflectors)+685 System.Web.Services.Description.ServiceDescriptionReflector.Reflect(类型,字符串url)+118 System.Web.Services.Protocols.DocumentationServerType..ctor(类型类型,字符串uri,布尔excludeSchemeHostPortFromCachingKey)+230 System.Web.Services.Protocols.DocumentationServerProtocol.Initialize()+434 创建(类型类型、HttpContext上下文、HttpRequest请求、HttpResponse响应、布尔和中止处理)+122

[无效操作异常:无法处理请求。] 创建(类型类型、HttpContext上下文、HttpRequest请求、HttpResponse响应、布尔和中止处理)+320 System.Web.Services.Protocols.WebServiceHandlerFactory.CoreGetHandler(类型类型,HttpContext上下文,HttpRequest请求,HttpResponse响应)+171

public class ProfileObject { public Person Person { get; set; } public IEnumerable<Node<Language>> Language { get; set; } public IEnumerable<Node<Country>> Country { get; set; } }

public Country Country {get; set;} 
public class ProfileObject
{
    public Person Person { get; set; }

    [XmlIgnore]
    public IEnumerable<Node<Language>> Language { get; set; }

    [XmlIgnore]
    public IEnumerable<Node<Country>> Country { get; set; }

    [XmlArray("Languages")]
    [XmlArrayItem("Language")]
    [Browsable(false), EditorBrowsable(EditorBrowsableState.Never), DebuggerBrowsable(DebuggerBrowsableState.Never)]
    public Node<Language>[] LanguageArray
    {
        get
        {
            if (Language == null)
                return null;
            return Language.ToArray();
        }
        set
        {
            Language = value;
        }
    }

    [XmlArray("Countries")]
    [XmlArrayItem("Country")]
    [Browsable(false), EditorBrowsable(EditorBrowsableState.Never), DebuggerBrowsable(DebuggerBrowsableState.Never)]
    public Node<Country>[] CountryArray
    {
        get
        {
            if (Country == null)
                return null;
            return Country.ToArray();
        }
        set
        {
            Country = value;
        }
    }
}
public static class NodeExtensions
{
    public static TData [] ToDataArray<TData>(this IEnumerable<Node<TData>> nodes)
    {
        if (nodes == null)
            return null;
        return nodes.Select(n => n.Data).ToArray();
    }
}

public class ProfileObject
{
    public Person Person { get; set; }

    [XmlIgnore]
    public IEnumerable<Node<Language>> Language { get; set; }

    [XmlIgnore]
    public IEnumerable<Node<Country>> Country { get; set; }

    [XmlArray("ArrayOfLanguage")]
    [XmlArrayItem("Language")]
    [Browsable(false), EditorBrowsable(EditorBrowsableState.Never), DebuggerBrowsable(DebuggerBrowsableState.Never)]
    public Language [] LanguageArray
    {
        get
        {
            return Language.ToDataArray();
        }
        set
        {
            throw new NotImplementedException();
        }
    }

    [XmlArray("ArrayOfCountry")]
    [XmlArrayItem("Country")]
    [Browsable(false), EditorBrowsable(EditorBrowsableState.Never), DebuggerBrowsable(DebuggerBrowsableState.Never)]
    public Country [] CountryArray
    {
        get
        {
            return Country.ToDataArray();
        }
        set
        {
            throw new NotImplementedException();
        }
    }
}
public class Country
{
    public string Name { get; set; }
}

public class Language
{
    public string Name { get; set; }
}

public class ProfileObject
{
    public Person Person { get; set; }
    public IEnumerable<Node<Language>> Language { get; set; }
    public IEnumerable<Node<Country>> Country { get; set; }
}

public class Person
{
    public int Id { get; set; }
    public string Email { get; set; }
}
(PERSON)-[:SPEAKS]->(ENGLISH)
(PERSON)-[:SPEAKS]->(GERMAN)
(PERSON)-[:CURRENT_LOCATION]->(GERMANY)
MATCH (person:Person)
WHERE (person.Email = "THE EMAIL ADDRESS HERE")
OPTIONAL MATCH (person)-[:SPEAKS]-(language:Language)
OPTIONAL MATCH (person)-[:CURRENT_LOCATION]-(country:Country)
RETURN person AS Person, collect(language) AS Language, collect(country) AS Country