[英]cannot be serialized because it does not have a parameterless constructor
我正在調用作為WebReference添加到我的控制台測試應用程序中的SalesForce API。
它需要的參數之一是object類型。 確切地說,以下是我的代碼:
SFObject sfObject = new SFObject
{
type = "User",
Item = new { ExternalId = 2}
};
我通過上面的代碼,其中API期望Item的類型為object()。
當我進行最后通話時,看到以下錯誤:
{“ <> f__AnonymousType0`1 [System.Int32]無法序列化
下面是SFObject的定義,因為我下載了它的“添加Web參考” 。
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.6.81.0")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="urn:sfobject.sfapi.successfactors.com")]
public partial class SFObject {
private object itemField;
private string typeField;
private System.Xml.XmlElement[] anyField;
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute("businessKeys", typeof(BusinessKeys))]
[System.Xml.Serialization.XmlElementAttribute("id", typeof(string))]
public object Item {
get {
return this.itemField;
}
set {
this.itemField = value;
}
}
/// <remarks/>
public string type {
get {
return this.typeField;
}
set {
this.typeField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlAnyElementAttribute()]
public System.Xml.XmlElement[] Any {
get {
return this.anyField;
}
set {
this.anyField = value;
}
}
}
我四處搜尋,似乎WCF序列化有問題,但是我在這里沒有使用WCf。 有什么辦法可以解決這個問題?
簡短的答案就在下面的代碼中:
[System.Xml.Serialization.XmlElementAttribute("businessKeys", typeof(BusinessKeys))]
[System.Xml.Serialization.XmlElementAttribute("id", typeof(string))]
public object Item {
get {
return this.itemField;
}
set {
this.itemField = value;
}
}
哪里
[System.Xml.Serialization.XmlElementAttribute("businessKeys", typeof(BusinessKeys))]
[System.Xml.Serialization.XmlElementAttribute("id", typeof(string))]
它的一部分要求它是String類型或BusinessKeys類型。 如果發送了其他任何內容,則它將被拒絕為意外類型。 如果您嘗試使用new {}關鍵字欺騙系統,那么它將拋出剛剛拋出的錯誤。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.