首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Dynamics CRM插件错误教程

Dynamics CRM插件错误教程
EN

Stack Overflow用户
提问于 2013-06-05 05:46:49
回答 1查看 3K关注 0票数 0

我正在尝试使用本教程编写我的第一个插件:

http://msdn.microsoft.com/en-us/library/gg695782.aspx

但是,在注册时,我在保存联系人时收到此错误。

代码语言:javascript
复制
Culture=neutral, PublicKeyToken=31bf3856ad364e35]]: Unexpected exception from plug-in (Execute): Plugin: System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.Xrm.Client, Version=5.0.9689.2166, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.Detail: 
 <OrganizationServiceFault xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.microsoft.com/xrm/2011/Contracts"> 
 <ErrorCode>-2147220956</ErrorCode> 
 <ErrorDetails xmlns:d2p1="http://schemas.datacontract.org/2004/07/System.Collections.Generic" /> 
 <Message>Unexpected exception from plug-in (Execute): Plugin: System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.Xrm.Client, Version=5.0.9689.2166, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.</Message> 
 <Timestamp>2013-06-03T19:23:50.6212306Z</Timestamp> 
 <InnerFault i:nil="true" /> 
 <TraceText> 

 [PluginWalkthrough: Plugin] 
 [b40b42a2-82cc-e211-8bf1-984be16dae4d: Plugin: Create of contact] 


 </TraceText> 
 </OrganizationServiceFault>

当我使用CRM Online时,Microsoft.Xrm.Client程序集应该已经在GAC中准备好了。我被困在这里了,请帮帮我,我做错了什么?

代码如下:

代码语言:javascript
复制
using System;
using System.Diagnostics;
using System.Linq;
using System.ServiceModel;
using Microsoft.Xrm.Sdk;
using Xrm;

public class Plugin : IPlugin
{
    public void Execute(IServiceProvider serviceProvider)
    {
        IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));

        Entity entity;

        // Check if the input parameters property bag contains a target
        // of the create operation and that target is of type Entity.
        if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity)
        {
            // Obtain the target business entity from the input parameters.
            entity = (Entity)context.InputParameters["Target"];

            // Verify that the entity represents a contact.
            if (entity.LogicalName != "contact") { return; }
        }
        else
        {
            return;
        }

        try
        {
            IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
            IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);

            var id = (Guid)context.OutputParameters["id"];

            AddNoteToContact(service, id);
        }
        catch (FaultException<OrganizationServiceFault> ex)
        {
            throw new InvalidPluginExecutionException(
            "An error occurred in the plug-in.", ex);
        }
    }

    private static void AddNoteToContact(IOrganizationService service, Guid id)
    {
        using (var crm = new XrmServiceContext(service))
        {

            var contact = crm.ContactSet.Where(c => c.ContactId == id).First();
            Debug.Write(contact.FirstName);

            var note = new Annotation
            {
                Subject = "Created with plugin",
                NoteText = "This Note was created by the example plug-in",
                ObjectId = contact.ToEntityReference(),
                ObjectTypeCode = contact.LogicalName
            };

            crm.AddObject(note);
            crm.SaveChanges();
        }
    }
}

这是我的推荐人的截图:

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-06-05 06:43:04

谢谢你的帮助!通过重新生成Xrm.cs修复了它,虽然仍然不确定这个Xrm.cs有什么不同,但它可以工作。使用以下命令重新生成:

crmsvcutil.exe /out:Xrm\Xrm.cs /url:https://mydomain.api.crm4.dynamics.com/XRMServices/2011/Organization.svc /username:martijn@mydomain.onmicrosoft.com /password:itssecret /namespace:Xrm /serviceContextName:XrmServiceContext

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/16928056

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档