locked
PlugIn is not created : Missing assembly refernce and Could not copy file (path).dll beacuse it was not found RRS feed

  • Question

  • Hi all,

    I am trying to replicate the following article for account entity.

    CRM Plugin Tutorial

    http://blog.developers.ba/develop-create-update-plugin-dynamics-crm-2013/

    But I am getting folllowing errors:-
    Missing assembly refernce and could not copy file (path).dll beacuse it was not found.

    Please help what I am mssing???

    // <copyright file="PostAccountCreate.cs" company="IBM">
    // Copyright (c) 2016 All Rights Reserved
    // </copyright>
    // <author>IBM</author>
    // <date>4/20/2016 3:00:55 PM</date>
    // <summary>Implements the PostAccountCreate Plugin.</summary>
    // <auto-generated>
    // This code was generated by a tool.
    // Runtime Version:4.0.30319.1
    // </auto-generated>
    using
    System;
    using
    System.ServiceModel;
    using
    Microsoft.Xrm.Sdk;
    using
    Microsoft.Xrm.Sdk.Client;
    using
    Microsoft.Xrm.Sdk.Query;
    using
    System.Net;
    using
    System.Text;
    using
    System.IO;
    using
    System.Globalization;
    using
    Microsoft.Crm.Sdk;
    using
    System.Collections.ObjectModel;
    using
    System.Globalization;
    using
    System.Linq;
     
    namespace
    CrmVSSolution3.Plugins
    {
    /// <summary>
    /// PostAccountCreate Plugin.
    /// </summary> 
    public class PostAccountCreate: Plugin
    {
    /// <summary>
    /// Initializes a new instance of the <see cref="PostAccountCreate"/> class.
    /// </summary>
    public PostAccountCreate()
    :
    base(typeof(PostAccountCreate))
    {
    base.RegisteredEvents.Add(new Tuple<int, string, string, Action<LocalPluginContext>>(40, "Create", "account", new Action<LocalPluginContext>(ExecutePostAccountCreate)));
    // Note : you can register for more events here if this plugin is not specific to an individual entity and message combination.
    // You may also need to update your RegisterFile.crmregister plug-in registration file to reflect any change.
    }
    /// <summary>
    /// Executes the plug-in.
    /// </summary>
    /// <param name="localContext">The <see cref="LocalPluginContext"/> which contains the
    /// <see cref="IPluginExecutionContext"/>,
    /// <see cref="IOrganizationService"/>
    /// and <see cref="ITracingService"/>
    /// </param>
    /// <remarks>
    /// For improved performance, Microsoft Dynamics CRM caches plug-in instances.
    /// The plug-in's Execute method should be written to be stateless as the constructor
    /// is not called for every invocation of the plug-in. Also, multiple system threads
    /// could execute the plug-in at the same time. All per invocation state information
    /// is stored in the context. This means that you should not use global variables in plug-ins.
    /// </remarks>
    //create plugin for CRM 2013 
    //To generate “Insert / Create plugin” choose pipeline stage Post-Operation and message Create.
    //create plugin for entity Account,which contains optionset and lookup field.
    //This Create Plugin is used to call our REST Web API to exchange data between CRM and our third party system.
    protected void ExecutePostAccountCreate(LocalPluginContext localContext)
    {
    if (localContext == null)
    {
    throw new ArgumentNullException("localContext");
    }
    // TODO: Implement your custom Plug-in business logic.
    if (localContext == null)
    {
    throw new ArgumentNullException("localContext");
    }
    // TODO: Implement your custom Plug-in business logic.
    var context = localContext.PluginExecutionContext; 
    // if user is our web api user return to prevent recursive call 
    if (context.InitiatingUserId.ToString().Equals("2f2c9848-194a-e411-80cc-00155d0c03cf")) 
    {
    return; 
    }
    IOrganizationService service = localContext.OrganizationService;
    if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity)
    {
    Entity entity = (Entity)context.InputParameters["Target"];
    if (entity.LogicalName == "account")
    {
    try
    {
    if (entity.Attributes.Contains("name") && entity.Attributes.Contains("accountid") && entity.Attributes.Contains("territorycode") && entity.Attributes.Contains("territoryid"))
    {
    CustomAccount d =
    new CustomAccount();
    d.Terr_Name = (
    string)entity.Attributes["territorycode"];
    d.Terr_Id = (
    string)entity.Attributes["territoryid"];
    // here we grab optionset value 
    d.Terr_Name = entity.GetAttributeValue<
    OptionSetValue>("territorycode").Value.ToString();
    // here we grab lookup value for field region 
    d.Terr_Id = (
    string)entity.Attributes["territoryid"];
    // here we call our external web api and pass municipality entity to be created 
    var customAccountRepository = new CustomAccountRepository();
    var result = customAccountRepository.Insert(d);
    if (!string.IsNullOrWhiteSpace(result))
    {
    throw new InvalidPluginExecutionException("Error with calling Web API occured: " + result);
    }
    // We do not call service to update entity becouse no data in entity is changed. If we need to change entity fields before save do so like this://
    // entity.Attributes["name"] = "My new name of Account";
    // and then call service to update previously created entity // 
    // service.Update(entity);
    }
    else
    {
    throw new InvalidPluginExecutionException("Some required field missing");
    }
    }
    catch (FaultException ex)
    {
    throw new InvalidPluginExecutionException("An error occured in create plugin: " + ex.ToString());
    }
    catch (Exception ex)
    {
    throw new InvalidPluginExecutionException("An error occured in create plugin: " + ex.ToString());
    }
    }
    else
    {
    throw new InvalidPluginExecutionException("Entity does not exists");
    }
    }
    }
    }
    
    Refernces :
    Microsoft.Crm.Sdk.Proxy
    Microsft.CSharp
    Microsft.Xrm.Sdk
    System.ServiceModel
    


    
    Thursday, April 21, 2016 10:33 AM