我正在從CRM 2011中檢索一些數據。我有一個帶有對我的組織的服務引用的Windows窗體應用程序。CRM 2011:更新實體時的序列化例外
query = new QueryByAttribute();
query.EntityName = "myentityname";
cset = new ColumnSet();
cset.AllColumns = true;
cset.Columns = new string[] { "" };
query.ColumnSet = cset;
query.Attributes = new string[] { "col1", "col2" };
query.Values = new object[] { col1.value, col2.value };
result = (EntityCollection)_service.RetrieveMultiple(query);
的 「retrieveMultiple」 拋出下面的異常:
The formatter threw an exception while trying to deserialize the message: There was an error while trying to deserialize parameter
http://schemas.microsoft.com/xrm/2011/Contracts/Services:RetrieveMultipleResult. The InnerException message was 'Error in line 1 position 833.
Element 'http://schemas.datacontract.org/2004/07/System.Collections.Generic:value' contains data from a type that maps to the name 'http://schemas.microsoft.com/xrm/2011/Contracts:OptionSetValue'.
The deserializer has no knowledge of any type that maps to this name. Consider using a DataContractResolver or add the type corresponding
to 'OptionSetValue' to the list of known types - for example, by using the KnownTypeAttribute attribute or by adding it to the list of known types passed to DataContractSerializer.'.
Please see InnerException for more details.
我做了一些網上搜索,並最終移除「cset.AllColumns = TRUE;並更換 「」 在query.columns與。該實體的列名的一個這個工作很好,但隨後我的代碼的其餘部分將導致錯誤
if (result.Entities.Length > 0)
{
Entity myentity= new Entity();
myentity.LogicalName = "EntityName";
myentity.Attributes = new AttributeCollection();
//record exists, update
myentity.Id = (result.Entities[0]).Id;
myentity.Attributes.Add(new KeyValuePair<string, object> ("myentityid", ((Entity)result.Entities[0]).Id));
_service.Update(myentity);
}
這一次「更新」方法拋出這個異常:
There was an error while trying to serialize parameter http://schemas.microsoft.com/xrm/2011/Contracts/Services:entity.
The InnerException message was 'Type 'CRM_Populi_Integration.CRMSer.EntityReference' with data contract name 'EntityReference:http://schemas.microsoft.com/xrm/2011/Contracts' is not expected.
Consider using a DataContractResolver or add any types not known statically to the list of known types - for example, by using the KnownTypeAttribute attribute or by adding them to the list of known types passed to DataContractSerializer.'.
Please see InnerException for more details.
我不明白這個serielization錯誤背後的原因,我不知道如何解決它。
注意: 此應用程序在另一臺服務器上工作正常,我只是將應用程序複製並粘貼到另一臺服務器中,並更新了服務引用,並且這些異常開始出現。
你能幫我嗎?
感謝