我想爲MS CRM運行一個示例插件。但我收到以下錯誤:MS CRM插件的一般錯誤
An error occurred. Contact a system administrator or refer to the Microsoft Dynamics CRM SDK troubleshooting guide.
這裏是代碼:
public void Execute(IServiceProvider serviceProvider)
{
// Obtain the execution context from the service provider.
IPluginExecutionContext context = (IPluginExecutionContext)
serviceProvider.GetService(typeof(IPluginExecutionContext));
// The InputParameters collection contains all the data passed in the message request.
if (context.InputParameters.Contains("account") &&
context.InputParameters["account"] is Entity)
{
// Obtain the target entity from the input parmameters.
Entity entity = (Entity)context.InputParameters["account"];
try
{
//check if the account number exist
if (entity.Attributes.Contains("account number") == false)
{
//create a task
Entity task = new Entity("task");
task["subject"] = "Account number is missing";
task["regardingobjectid"] = new EntityReference("account", new Guid(context.OutputParameters["id"].ToString()));
//adding attribute using the add function
// task["description"] = "Account number is missng for the following account. Please enter the account number";
task.Attributes.Add("description", "Account number is missng for the following account. Please enter the account number");
// Obtain the organization service reference.
IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);
// Create the task in Microsoft Dynamics CRM.
service.Create(task);
}
}
catch (FaultException ex)
{
throw new InvalidPluginExecutionException("An error occurred in the plug-in.", ex);
}
}
}
}//end class
這是一個示例代碼,我覈實,這是由這個插件使用的全部實體和字段定義並在那裏的地方。但我不斷收到此業務錯誤。
你的代碼中有幾個邏輯錯誤(例如,你需要在'InputParameters'而不是'account'內查找'Target'屬性),但是由於這些錯誤,你當前的代碼將不會執行任何操作,我最好的猜測是你的目標框架是4.5而不是4.0。另外,您可以嘗試運行此示例:http://msdn.microsoft.com/en-us/library/gg594416.aspx –