第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Web 服務(wù)方法 - 無法序列化,因為它沒有無參數(shù)構(gòu)造函數(shù)

Web 服務(wù)方法 - 無法序列化,因為它沒有無參數(shù)構(gòu)造函數(shù)

C#
尚方寶劍之說 2021-11-21 16:08:57
我在我的 .net 項目中添加了一個 web 引用,其中包含 3rd 方服務(wù)的方法。當(dāng)我嘗試調(diào)用其中一種方法時,它期望傳遞一個 OrderIdentifier 對象,但它給了我錯誤:InvalidOperationException: <>f__AnonymousType0`3[System.DateTime,ETS_OpenAccessNew.ETS.DateRange,ETS_OpenAccessNew.ETS.AuctionIdentification] 無法序列化,因為它沒有無參數(shù)構(gòu)造函數(shù)。我的代碼如下:        OrderIdentifier oi = new OrderIdentifier        {            area = testArea,            portfolio = testPortfolio        };        DateRange dr = new DateRange { from = DateTime.Today.AddDays(-7), to = DateTime.Today };        var Ai = new AuctionIdentification        {            Item = DateTime.Today.AddDays(-1),            ItemElementName = ItemChoiceType1.AuctionDate,            name = "test",            duration = AuctionIdentificationDuration.Item30min,            durationSpecified = true        };        object items = new        {            deliveryDay = DateTime.Today.AddDays(-1),            deliveryDays = dr,            AuctionIdentification = Ai        };         oi.Items = new object[1] { items };        var orders = oa.RetrieveOrders(oi);任何關(guān)于我在這里做錯的想法將不勝感激更新 - 我現(xiàn)在已經(jīng)將無參數(shù)構(gòu)造函數(shù)包含在 AuctionIdentification 類中,但仍然出現(xiàn)相同的錯誤
查看完整描述

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

};


查看完整回答
反對 回復(fù) 2021-11-21
?
斯蒂芬大帝

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

};


查看完整回答
反對 回復(fù) 2021-11-21
  • 2 回答
  • 0 關(guān)注
  • 521 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號