2013-06-04 2 views
0

Я пытаюсь написать свой первый плагин с помощью этого учебника:Dynamics CRM ошибка с плагином учебник

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

Однако, при регистрации я получаю эту ошибку при сохранении контакта.

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 Allready. Я застрял здесь, пожалуйста, помогите мне, что я делаю неправильно ???

Вот код:

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(); 
     } 
    } 
} 

А вот скриншот из моих ссылок:

Screenshot of References

+0

Очень странно, что у вас все еще есть эти проблемы, можете ли вы разместить свой код (также с использованием) и снимок экрана со ссылками в вашем проекте? –

+0

Обновлено сообщение. Надеюсь это поможет. –

+0

Очень редко даже требуется Microsoft.Xrm.Client в плагине. Что происходит, когда вы удаляете ссылку? – TeaDrivenDev

ответ

0

Спасибо за помощь! Исправлено его, обновив Xrm.cs. Все еще не уверен, что отличает этот Xrm.cs, но он работает. Восстановленная с помощью этой команды:

crmsvcutil.exe /out:Xrm\Xrm.cs /URL: https://mydomain.api.crm4.dynamics.com/XRMServices/2011/Organization.svc /username:[email protected]/пароль: itssecret /Пространство имен: XRM/serviceContextName: XrmServiceContext

+0

рад, что вы решили :) –

+0

Еще раз. Спасибо за всю помощь Гвидо! –

Смежные вопросы