CRM插件,系统找不到指定的文件
CRM Plugin,system cannot find the file specified
我正在创建一个 CRM 插件,它适用于作为 post 事件创建的案例。
我通过注册工具部署了插件,启用了沙箱,并选择数据库作为程序集的存储位置。
注:我在线使用的是CRM 2015。
弹出以下错误:
Unexpected exception from plug-in (Execute): cases_plugin.casereserve: System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.Xrm.Client, Version=7.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies.
这是代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Crm.Sdk;
using Microsoft.Xrm.Sdk;
using Microsoft.Crm.Sdk.Messages;
using Microsoft.Xrm.Sdk.Query;
using Xrm;
namespace cases_plugin
{
public class casereserve : IPlugin
{
public void Execute(IServiceProvider serviceProvider)
{
int count = 0;
int min = 100000000;
var xrm = new XrmServiceContext("Xrm");
IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
IOrganizationServiceFactory serviceFactory =
(IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);
Entity targetEntity = null;
if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity)
{
targetEntity = context.InputParameters["Target"] as Entity;
if (context.MessageName != "Create")
return;
if (context.PrimaryEntityName != "incident")
return;
}
Incident currentcase = targetEntity.ToEntity<Incident>();
SystemUser useruse= new SystemUser();
var users = from user in xrm.SystemUserSet where user.new_CaseTypeResponsipelty ==currentcase.CaseTypeCode select user;
foreach (var useritm in users)
{
var caseno = from cases in xrm.IncidentSet where cases.OwningUser.Id == useritm.Id && (cases.StatusCode == 5 || cases.StatusCode == 1000 || cases.StatusCode == 6 || cases.StatusCode == 2000) select cases;
foreach (var caseitm in caseno)
{
count++;
}
if (count < min)
{
min = count;
useruse.Id = useritm.Id;
useruse.FirstName = useritm.FirstName;
}
count = 0;
}
AssignRequest assign = new AssignRequest
{
Assignee = new EntityReference(SystemUser.EntityLogicalName,
useruse.Id),
Target = new EntityReference(Incident.EntityLogicalName,
currentcase.Id)
};
xrm.Execute(assign);
}
}
}
删除对 Microsoft.Xrm.Client 程序集的引用。
我正在创建一个 CRM 插件,它适用于作为 post 事件创建的案例。
我通过注册工具部署了插件,启用了沙箱,并选择数据库作为程序集的存储位置。
注:我在线使用的是CRM 2015。
弹出以下错误:
Unexpected exception from plug-in (Execute): cases_plugin.casereserve: System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.Xrm.Client, Version=7.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies.
这是代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Crm.Sdk;
using Microsoft.Xrm.Sdk;
using Microsoft.Crm.Sdk.Messages;
using Microsoft.Xrm.Sdk.Query;
using Xrm;
namespace cases_plugin
{
public class casereserve : IPlugin
{
public void Execute(IServiceProvider serviceProvider)
{
int count = 0;
int min = 100000000;
var xrm = new XrmServiceContext("Xrm");
IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
IOrganizationServiceFactory serviceFactory =
(IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);
Entity targetEntity = null;
if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity)
{
targetEntity = context.InputParameters["Target"] as Entity;
if (context.MessageName != "Create")
return;
if (context.PrimaryEntityName != "incident")
return;
}
Incident currentcase = targetEntity.ToEntity<Incident>();
SystemUser useruse= new SystemUser();
var users = from user in xrm.SystemUserSet where user.new_CaseTypeResponsipelty ==currentcase.CaseTypeCode select user;
foreach (var useritm in users)
{
var caseno = from cases in xrm.IncidentSet where cases.OwningUser.Id == useritm.Id && (cases.StatusCode == 5 || cases.StatusCode == 1000 || cases.StatusCode == 6 || cases.StatusCode == 2000) select cases;
foreach (var caseitm in caseno)
{
count++;
}
if (count < min)
{
min = count;
useruse.Id = useritm.Id;
useruse.FirstName = useritm.FirstName;
}
count = 0;
}
AssignRequest assign = new AssignRequest
{
Assignee = new EntityReference(SystemUser.EntityLogicalName,
useruse.Id),
Target = new EntityReference(Incident.EntityLogicalName,
currentcase.Id)
};
xrm.Execute(assign);
}
}
}
删除对 Microsoft.Xrm.Client 程序集的引用。