【发布时间】:2013-04-22 23:07:54
【问题描述】:
我正在尝试使用以下代码将注释实体保存在 CRM 2011 中:
var annotationContext = new CrmOrganizationServiceContext(crmOrganizationService);
var annotation = annotationContext.CreateEntity("annotation");
annotationContext.AddObject(annotation);
// Setting the account id.
entity.SetAttributeValue<EntityReference>("objectid", "account", "Guid of the account");
entity.iCrmSetPropertyValue(AnnotationDefinition.ColumnsName.DocumentBody,Convert.ToBase64String(new UnicodeEncoding().GetBytes("Sample Annotation Text")));
entity.iCrmSetPropertyValue("isdocument",true);
entity.iCrmSetPropertyValue(AnnotationDefinition.ColumnsName.Mime, "text/plain");
entity.iCrmSetPickListValue(AnnotationDefinition.ColumnsName.ObjectType, 1);
entity.iCrmSetPropertyValue(AnnotationDefinition.ColumnsName.Subject, "CompanyLogo");
annotationContext.SaveChanges();
保存更改方法失败,在 crm 服务器的事件查看器中出现以下错误:
Web Service 插件在 OrganizationId 中失败:############; SdkMessageProcessingStepId: #####; EntityName:注解;阶段:30; 消息名称:创建;大会名称: Microsoft.Crm.Extensibility.InternalOperationPlugin, Microsoft.Crm.ObjectModel,版本=5.0.0.0,文化=中性, PublicKeyToken=31bf3856ad364e35;班级名称: Microsoft.Crm.Extensibility.InternalOperationPlugin;例外: 未处理的异常:System.InvalidCastException:指定的演员是 无效。在 Microsoft.Crm.BusinessEntities.EntityNameReferenceAttributeConverter.ConvertToBusinessEntity(对象 值,AttributeMetadata attributeMetadata,字典`2 abbrvToChildAttributeMetadata,ICrmConversionContext 上下文, BusinessEntity 目标)在 Microsoft.Crm.BusinessEntities.EntityToBusinessEntityConverter.ConvertUsingExistingBusinessEntity(EntityMetadata entityMetadata、ICrmConversionContext 转换上下文、实体 实体,BusinessEntity businessEntity)在 Microsoft.Crm.BusinessEntities.BusinessEntity.Converter.ConvertFrom(ITypeDescriptorContext 上下文,CultureInfo 文化,对象值)在 Microsoft.Crm.BusinessEntities.ConversionHelpers.Convert(ICrmConversionContext 转换上下文,对象源,类型destinationType)在 Microsoft.Crm.Extensibility.DictionaryMapper.Map(ParameterCollection 输入,ICrmConversionContext 上下文)在 Microsoft.Crm.Extensibility.InternalOperationPlugin.Execute(IServiceProvider 服务提供商)在 Microsoft.Crm.Extensibility.V5PluginProxyStep.ExecuteInternal(PipelineExecutionContext 上下文)在 Microsoft.Crm.Extensibility.VersionedPluginProxyStepBase.Execute(PipelineExecutionContext 上下文)
【问题讨论】:
-
你有类型冲突:
System.InvalidCastException: Specified cast is not valid -
您是在发送
"Guid of the account"还是只是为了演示目的?