2 回答

TA貢獻(xiàn)1860條經(jīng)驗 獲得超8個贊
異常的消息告訴你,你正在試圖序列匿名類型包含DateTime,DateRange以及AuctionIdentification性能和匿名類型的確沒有參數(shù)構(gòu)造函數(shù)(它們是不變的,所以他們的成員是通過構(gòu)造函數(shù)的參數(shù)初始化)。
有問題的匿名類型在items此處創(chuàng)建并分配給變量:
object items = new // <--
{
deliveryDay = DateTime.Today.AddDays(-1),
deliveryDays = dr,
AuctionIdentification = Ai
};
oi.Items = new object[1] { items };
根據(jù)Items屬性定義
[System.Xml.Serialization.XmlElementAttribute("AuctionIdentification", typeof(AuctionIdentification))]
[System.Xml.Serialization.XmlElementAttribute("deliveryDay", typeof(System.DateTime), DataType="date")]
[System.Xml.Serialization.XmlElementAttribute("deliveryDays", typeof(DateRange))]
public object[] Items {
get {
return this.itemsField;
}
set {
this.itemsField = value;
}
}
它的陣列objects,其中每個的實際類型object可以是所描述的3種類型中的一個- DateTime,DateRange和AuctionIdentification。
有點奇怪的設(shè)計,但這是 3rd 方服務(wù)的錯,而不是你的錯。在您的情況下正確的初始化(也應(yīng)該修復(fù)有問題的異常)應(yīng)該是直接填充數(shù)組:
oi.Items = new object[] // <--
{
DateTime.Today.AddDays(-1), // deliveryDay
dr, // deliveryDays
Ai // AuctionIdentification
};

TA貢獻(xiàn)1827條經(jīng)驗 獲得超8個贊
問題出在這一行:
DateRange dr = new DateRange { from = DateTime.Today.AddDays(-7), to = DateTime.Today };
您正在嘗試創(chuàng)建一個新實例,DateRange()但它不接受您的初始化,說明您無法初始化該類,因為它沒有無參數(shù)構(gòu)造函數(shù),因為您沒有提供任何構(gòu)造函數(shù)。
這個類的一個很好的例子是:
DateRange range = new DateRange(fromDate, toDate, CultureInfo);
或者:
return new DateRange
{
from = DateTime.Today.AddDays(-7),
to = DateTime.Today
};
- 2 回答
- 0 關(guān)注
- 521 瀏覽
添加回答
舉報