本文介绍了无法序列成员....因为它是一个接口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直有这个问题,并已拉出我的头发了它。我有跟随着错误:

I have changed all my IList's to List's to see if that would do anything, but it didnt, infact, it didnt even take a second to load after making those changes, im guessing because the error happens even before it gets to that part. I checked my remote files to see if it was uploading correctly and it was.

Here is the code:

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;
            }
        }
    }
}

The error happens when this code is activated:

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);
}

The CustomerAddress class:

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; }
}
}
解决方案

In the code you posted, the type of CustomerAddresses is IList<CustomerAdress>. That's an interface. Like the error message says, you can't serialize an interface.

这篇关于无法序列成员....因为它是一个接口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 12:32