ant*_*liu 20 c# xml-serialization
我一直有这个问题,一直把头发拉过来.我有以下错误:
异常详细信息:System.NotSupportedException:无法序列化类型为System.Collections.Generic.IList`1 [[HannaPrintsDataAccess.CustomerAddress,HannaPrintsDataAccess,Version = 1.0.0.0,Culture = neutral,PublicKeyToken = null]]的成员HannaPrintsDataAccess.Customer.CustomerAddresses,因为它是一个界面.
来源错误:
第196行:客户客户= OperationsManager.Instance.CustomerService.GetCustomer(7); 第197行:第198行:字符串xml = OperationsManager.Instance.CustomerService.GetCustomerAddressesXml(CustomerAddress.FindAll()); 第199行:第200行:订单订单= OperationsManager.Instance.OrderService.CreateOrderFromCart(xml);
源文件:c:\ HostingSpaces\greetwus\galadavetiye.com\wwwroot\HannaPrints\HannaPrints\WebUI\CreateGreetingCard.aspx.cs行:198
堆栈跟踪:
[NotSupportedException:无法序列化类型System.Collections.Generic.IList`1 [[HannaPrintsDataAccess.CustomerAddress,HannaPrintsDataAccess,Version = 1.0.0.0,Culture = neutral,PublicKeyToken = null]]的成员HannaPrintsDataAccess.Customer.CustomerAddresses,因为它是一个接口]
[InvalidOperationException:无法序列化'System.Collections.Generic.IList`1 [[HannaPrintsDataAccess.CustomerAddress,HannaPrintsDataAccess,Version = 1.0.0.0,Culture = neutral,PublicKeyToken = null]]'类型的成员'HannaPrintsDataAccess.Customer.CustomerAddresses',有关更多详细信息,请参阅内部异常.] System.Xml.Serialization.StructModel.CheckSupportedMember(TypeDesc typeDesc,MemberInfo成员,类型类型)+889917 System.Xml.Serialization.StructModel.GetPropertyModel(PropertyInfo propertyInfo)+132 ...... ..
我已经将我的所有IList更改为List's以查看它是否可以执行任何操作,但事实上,在进行这些更改之后它甚至没有花费一秒钟加载,我猜测因为错误甚至在它到达该部分之前发生.我检查了我的远程文件,看它是否正确上传,确实如此.
这是代码:
using System;
using System.Collections.Generic;
using Castle.ActiveRecord;
namespace HannaPrintsDataAccess {
public partial class Customer {
private 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;
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
激活此代码时会发生错误:
protected void orderButton_Click(object sender, EventArgs e)
{
Customer customer = OperationsManager.Instance.CustomerService.GetCustomer(7);
string xml = OperationsManager.Instance.CustomerService.GetCustomerAddressesXml(CustomerAddress.FindAll());
Order order = OperationsManager.Instance.OrderService.CreateOrderFromCart(xml);
OperationsManager.Instance.CartService.MoveCart("MyDesigns");
Response.Redirect("~/Customer/PayByCreditCard.aspx?orderGuid=" + order.OrderGuid);
}
Run Code Online (Sandbox Code Playgroud)
CustomerAddress类:
using System.IO;
using System.Xml.Serialization;
using Castle.ActiveRecord;
namespace HannaPrintsDataAccess
{
public partial class CustomerAddress
{
public string ToXml()
{
XmlSerializer serializer = new XmlSerializer(GetType());
MemoryStream memoryStream = new MemoryStream();
serializer.Serialize(memoryStream, this);
memoryStream.Seek(0, SeekOrigin.Begin);
return new StreamReader(memoryStream).ReadToEnd();
}
[BelongsTo("CustomerId")]
public virtual Customer Customer { get; set; }
}
}
Run Code Online (Sandbox Code Playgroud)