0
我想創建一個地址記錄,但我不斷收到錯誤。MS CRM:創建地址記錄不正確的屬性值類型錯誤
The application terminated with an error.
Code: -2147220989
Message: Incorrect attribute value type System.Int32
的代碼如下
public const int OBJECT_TYPE_CONTACT = 2;
int addressTypeCode = 3; //Primary Address
if (i == 2) addressTypeCode = 1; //Billing Address
if (i == 3) addressTypeCode = 2; //Shipping Address
Entity newAddress = new Entity("customeraddress");
newAddress.Attributes["parentid"] = new EntityReference("contact", existingContact.Id);
newAddress.Attributes["addresstypecode"] = addressTypeCode;
newAddress.Attributes["objecttypecode"] = OBJECT_TYPE_CONTACT;
newAddress.Attributes["line1"] = "temp1";
newAddress.Attributes["line2"] = "temp2";
newAddress.Attributes["line3"] = "temp3";
newAddress.Attributes["city"] = "temp3";
newAddress.Attributes["stateorprovince"] = "temp3";
newAddress.Attributes["postalcode"] = "temp3";
newAddress.Attributes["country"] = "temp3";
Guid id = service.Create(newAddress);
上設置objecttypecode線上的錯誤引發。我知道錯誤代碼的意思是「無效的參數」。在解決方案2指的是聯繫人,所以我沒有看到問題是什麼。
錯誤實際上是拋出行'Guid id = service.Create(newAddress);'。該錯誤永遠不會拋出在Entity.Attributes集合中添加/修改項目,因爲Entity類沒有類型意識。如果您使用早期綁定類型(來自'CrmSvcUtil.exe'),將會給你類型警告。 – Nicknow