【发布时间】:2014-12-30 10:14:17
【问题描述】:
我正在制作一个 Windows Phone 8.1 Silverlight 应用程序。我想要 LinkedIn 身份验证。我从互联网上获得了 1-3 个样本。但他们都在同一行报告错误:
using System.Xml.Serialization;
personXerializer = new XmlSerializer(typeof(SampleLinkedApp.Data.person));
给我错误:
System.Xml.Serialization.ni.dll 中出现“System.InvalidOperationException”类型的异常,但未在用户代码中处理 附加信息:存在错误反映类型 'SampleLinkedApp.Data.person'。
另外, person.cs:
[XmlRoot("person")]
public class person
{
[XmlElement("first-name")]
public string FirstName { get; set; }
[XmlElement("last-name")]
public string LastName { get; set; }
[XmlElement("headline")]
public string Headline { get; set; }
[XmlElement("headline")]
public string Interests { get; set; }
}
问题出在哪里?
还为这个问题添加了内部异常:
{System.InvalidOperationException: There was an error reflecting property 'Interests'. ---> System.InvalidOperationException: The XML element 'headline' from namespace '' is already present in the current scope. Use XML attributes to specify another XML name or namespace for the element.
at System.Xml.Serialization.XmlReflectionImporter.AddUniqueAccessor(INameScope scope, Accessor accessor)
at System.Xml.Serialization.XmlReflectionImporter.AddUniqueAccessor(MemberMapping member, INameScope elements, INameScope attributes, Boolean isSequence)
at System.Xml.Serialization.XmlReflectionImporter.InitializeStructMembers(StructMapping mapping, StructModel model, Boolean openModel, String typeName, RecursionLimiter limiter)
--- End of inner exception stack trace ---
at System.Xml.Serialization.XmlReflectionImporter.InitializeStructMembers(StructMapping mapping, StructModel model, Boolean openModel, String typeName, RecursionLimiter limiter)
at System.Xml.Serialization.XmlReflectionImporter.ImportStructLikeMapping(StructModel model, String ns, Boolean openModel, XmlAttributes a, RecursionLimiter limiter)
at System.Xml.Serialization.XmlReflectionImporter.ImportTypeMapping(TypeModel model, String ns, ImportContext context, String dataType, XmlAttributes a, Boolean repeats, Boolean openModel, RecursionLimiter limiter)}
【问题讨论】:
标签: c# xml windows-phone-8.1 linkedin xmlserializer