CRM插件,系统找不到指定的文件

时间:2015-08-13 19:36:32

标签: c# linq plugins crm

我正在创建一个CRM插件,用于将案例创建作为帖子事件 我通过注册工具部署了插件,启用了沙盒,我选择数据库作为程序集的存储位置。 注意:我在线使用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);

        }
    }
}

1 个答案:

答案 0 :(得分:2)

删除对Microsoft.Xrm.Client程序集的引用。