【发布时间】:2020-01-21 00:00:28
【问题描述】:
我不断收到此错误:
异常详情: System.NotSupportedException:不能 序列化成员 HannaPrintsDataAccess.Customer.CustomerAddresses 类型 System.Collections.Generic.IList`1[[HannaPrintsDataAccess.CustomerAddress, HannaPrintsDataAccess, 版本=1.0.0.0,文化=中性, PublicKeyToken=null]] 因为它是 界面。
这是堆栈跟踪: [NotSupportedException: 不能 序列化成员 HannaPrintsDataAccess.Customer.CustomerAddresses 类型 System.Collections.Generic.IList`1[[HannaPrintsDataAccess.CustomerAddress, HannaPrintsDataAccess, 版本=1.0.0.0,文化=中性, PublicKeyToken=null]] 因为它是 界面。]
[InvalidOperationException:不能 序列化成员 'HannaPrintsDataAccess.Customer.CustomerAddresses' 类型 'System.Collections.Generic.IList`1[[HannaPrintsDataAccess.CustomerAddress, HannaPrintsDataAccess, 版本=1.0.0.0,文化=中性, PublicKeyToken=null]]',见内部 更多细节例外。]
System.Xml.Serialization.StructModel.CheckSupportedMember(TypeDesc typeDesc,MemberInfo 成员,类型 类型)+889917
System.Xml.Serialization.StructModel.GetPropertyModel(PropertyInfo 物业信息)+132
System.Xml.Serialization.StructModel.GetFieldModel(MemberInfo 会员信息)+129
System.Xml.Serialization.XmlReflectionImporter.InitializeStructMembers(结构映射 映射,StructModel 模型,布尔值 openModel,字符串类型名称, RecursionLimiter 限制器)+1226
System.Xml.Serialization.XmlReflectionImporter.ImportStructLikeMapping(StructModel 模型,字符串 ns,布尔型 openModel, XmlAttributes a, RecursionLimiter 限制器)+460
System.Xml.Serialization.XmlReflectionImporter.ImportTypeMapping(TypeModel 模型,字符串 ns,ImportContext 上下文,字符串数据类型, XmlAttributes a,布尔重复, 布尔型 openModel、RecursionLimiter 限制器)+1415[InvalidOperationException:有 错误反映类型 'HannaPrintsDataAccess.Customer'。]
System.Xml.Serialization.XmlReflectionImporter.ImportTypeMapping(TypeModel 模型,字符串 ns,ImportContext 上下文,字符串数据类型, XmlAttributes a,布尔重复, 布尔型 openModel、RecursionLimiter 限制器)+1621
System.Xml.Serialization.XmlReflectionImporter.ImportAccessorMapping(成员映射 访问器,FieldModel 模型, XmlAttributes a, String ns, Type 选择标识符类型,布尔 rpc, 布尔型 openModel、RecursionLimiter 限制器)+10296
System.Xml.Serialization.XmlReflectionImporter.ImportFieldMapping(StructModel 父级,FieldModel 模型, XmlAttributes a, String ns, RecursionLimiter 限制器)+139
System.Xml.Serialization.XmlReflectionImporter.InitializeStructMembers(结构映射 映射,StructModel 模型,布尔值 openModel,字符串类型名称, RecursionLimiter 限制器)+1273[InvalidOperationException:有 反映属性的错误 '客户'。]
System.Xml.Serialization.XmlReflectionImporter.InitializeStructMembers(结构映射 映射,StructModel 模型,布尔值 openModel,字符串类型名称, RecursionLimiter 限制器)+2167
System.Xml.Serialization.XmlReflectionImporter.ImportStructLikeMapping(StructModel 模型,字符串 ns,布尔型 openModel, XmlAttributes a, RecursionLimiter 限制器)+460
System.Xml.Serialization.XmlReflectionImporter.ImportTypeMapping(TypeModel 模型,字符串 ns,ImportContext 上下文,字符串数据类型, XmlAttributes a,布尔重复, 布尔型 openModel、RecursionLimiter 限制器)+1415[InvalidOperationException:有 错误反映类型 'HannaPrintsDataAccess.CustomerAddress'。] System.Xml.Serialization.XmlReflectionImporter.ImportTypeMapping(TypeModel 模型,字符串 ns,ImportContext 上下文,字符串数据类型, XmlAttributes a,布尔重复, 布尔型 openModel、RecursionLimiter 限制器)+1621
System.Xml.Serialization.XmlReflectionImporter.CreateArrayElementsFromAttributes(ArrayMapping 数组映射,XmlArrayItemAttributes 属性,类型数组元素类型, 字符串 arrayElementNs, RecursionLimiter 限制器)+227
System.Xml.Serialization.XmlReflectionImporter.ImportArrayLikeMapping(ArrayModel 模型,字符串 ns,RecursionLimiter 限制器)+207
System.Xml.Serialization.XmlReflectionImporter.ImportTypeMapping(TypeModel 模型,字符串 ns,ImportContext 上下文,字符串数据类型, XmlAttributes a,布尔重复, 布尔型 openModel、RecursionLimiter 限制器)+1143[InvalidOperationException:有 错误反映类型 'HannaPrintsDataAccess.CustomerAddress[]'。] System.Xml.Serialization.XmlReflectionImporter.ImportTypeMapping(TypeModel 模型,字符串 ns,ImportContext 上下文,字符串数据类型, XmlAttributes a,布尔重复, 布尔型 openModel、RecursionLimiter 限制器)+1621
System.Xml.Serialization.XmlReflectionImporter.ImportTypeMapping(TypeModel 模型,字符串 ns,ImportContext 上下文,字符串数据类型, XmlAttributes a, RecursionLimiter 限制器)+28
System.Xml.Serialization.XmlReflectionImporter.ImportElement(TypeModel 模型,XmlRootAttribute 根,字符串 默认命名空间,递归限制器 限制器)+125
System.Xml.Serialization.XmlReflectionImporter.ImportTypeMapping(类型 类型,XmlRootAttribute 根,字符串 默认命名空间)+97
System.Xml.Serialization.XmlSerializer..ctor(类型 类型,字符串 defaultNamespace) +461
System.Xml.Serialization.XmlSerializer..ctor(类型 类型)+6
HannaPrintsBusiness.Services.Live.CustomerService.GetCustomerAddressesXml(CustomerAddress[] 客户地址)在 E:\ProjectsOld\HannaPrints\HannaPrintsBusiness\Services\Live\CustomerService.cs:148 CreateGreetingCard.orderButton_Click(对象 发件人,EventArgs e) 在 c:\HostingSpaces\greetwus\galadavetiye.com\wwwroot\HannaPrints\HannaPrints\WebUI\CreateGreetingCard.aspx.cs:198 System.Web.UI.WebControls.Button.OnClick(EventArgs e) +111
System.Web.UI.WebControls.Button.RaisePostBackEvent(字符串 事件参数)+110
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(字符串 eventArgument) +10
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler 源控件,字符串事件参数) +13 System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36
System.Web.UI.Page.ProcessRequestMain(布尔值 includeStagesBeforeAsyncPoint,布尔值 includeStagesAfterAsyncPoint) +1565
我似乎无法弄清楚这一点,我很确定它只是一些需要更改的配置,因为在我们获得此代码之前,据说它工作正常,但我们无法弄清楚为什么会出现此错误。如果有人可以提供帮助,那就太好了。谢谢!!!
更新 我尝试将 IList 更改为 List,但它没有做任何事情。这是我的课程和客户地址:
客户类:::
using System;
使用 System.Collections.Generic; 使用 Castle.ActiveRecord;
命名空间 HannaPrintsDataAccess { 公共部分类客户 { 私有 IList _customerAddresses;
public CustomerAddress GetPrimaryCustomerAddress()
{
foreach (CustomerAddress address in _customerAddresses)
{
if (address.IsPrimary)
return address;
}
return null;
}
[HasMany(typeof(CustomerAddress), ColumnKey = "CustomerId", Table = "Customer")]
public virtual IList<CustomerAddress> CustomerAddresses
{
get
{
return this._customerAddresses;
}
set
{
this._customerAddresses = value;
}
}
}
}
这是客户地址类::::
using System.IO;
使用 System.Xml.Serialization; 使用 Castle.ActiveRecord;
命名空间 HannaPrintsDataAccess { 公共部分类 CustomerAddress { 公共字符串 ToXml() { XmlSerializer 序列化器 = new XmlSerializer(GetType()); MemoryStream memoryStream = new MemoryStream(); serializer.Serialize(memoryStream, this); memoryStream.Seek(0, SeekOrigin.Begin); 返回新的 StreamReader(memoryStream).ReadToEnd(); }
[BelongsTo("CustomerId")]
public virtual Customer Customer { get; set; }
}
}
再次感谢您的帮助
【问题讨论】: