web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

CRM Plugin not triggering

(0) ShareShare
ReportReport
Posted on by

Hi everyone,

I'm using CRM Online Trial version,

I've been trying to execute a plugin but its not working. Below is a plugin code for creating a record,

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

using Microsoft.Xrm.Sdk;

using System.Runtime.Serialization;

using System.ServiceModel;

using Microsoft.Xrm.Client;

namespace MyPlugin

{

   public class Plugin : IPlugin

   {

       public void Execute(IServiceProvider serviceProvider)

       {

           IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));

           IOrganizationServiceFactory factory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));

           Entity targetEntity = null;

           if(context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity)

           {

               targetEntity = (Entity)context.InputParameters["Target"];

               if(targetEntity.LogicalName!="new_entity1")

               {

                   return;

               }

           }

           else

           {

               return;

           }

           try

           {

               IOrganizationService service = factory.CreateOrganizationService(context.UserId);

               if(!targetEntity.Contains("new_name"))

               {

                   return;

               }

               string a = (string)targetEntity["new_name"];

               Entity account = new Entity();

               account.LogicalName = "new_entity2";

               account.Attributes.Add("new_name", a);

               service.Create(account);

           }

           catch(FaultException<OrganizationServiceFault>ex)

           {

               throw new InvalidPluginExecutionException(string.Concat("An error occured in plugin",ex.Message,Environment.NewLine,ex.StackTrace));

           }

           catch(Exception ex)

           {

               throw new InvalidPluginExecutionException(string.Concat("An error occured in plugin",ex.Message,Environment.NewLine,ex.StackTrace));

           }

       }

   }

}

I've registered this plugin on Create Message on Post Operation event. but while executing it throws an error as"Business Process Error",

" An error occured in pluginCould not load file or assembly 'Microsoft.Xrm.Client, Version=6.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified. at System.Reflection.RuntimeAssembly.GetExportedTypes(RuntimeAssembly assembly, ObjectHandleOnStack retTypes) at System.Reflection.RuntimeAssembly.GetExportedTypes() at Microsoft.Xrm.Sdk.KnownProxyTypesProvider.LoadKnownTypes(Assembly assembly) at Microsoft.Xrm.Sdk.KnownProxyTypesProvider.RegisterAssembly(Assembly assembly) at Microsoft.Xrm.Sdk.AssemblyBasedKnownProxyTypesProvider.GetTypeForName(String name, Assembly proxyTypesAssembly) at Microsoft.Xrm.Sdk.ProxySerializationSurrogate.System.Runtime.Serialization.IDataContractSurrogate.GetObjectToSerialize(Object obj, Type targetType) at System.Runtime.Serialization.DataContractSerializer.InternalWriteObjectContent(XmlWriterDelegator writer, Object graph, DataContractResolver dataContractResolver) at System.Runtime.Serialization.DataContractSerializer.InternalWriteObject(XmlWriterDelegator writer, Object graph, DataContractResolver dataContractResolver) at System.Runtime.Serialization.XmlObjectSerializer.WriteObjectHandleExceptions(XmlWriterDelegator writer, Object graph, DataContractResolver dataContractResolver) at Microsoft.Crm.Sandbox.SandboxUtility.SerializeDataContract[T](T dataContract, Assembly proxyTypesAssembly) at Microsoft.Crm.Sandbox.SandboxOrganizationServiceWrapper.ExecuteInternal(OrganizationRequest request) at Microsoft.Crm.Sandbox.SandboxOrganizationServiceWrapper.CreateInternal(Entity entity) at MyPlugin.Plugin.Execute(IServiceProvider serviceProvider) "

Any Help??

*This post is locked for comments

I have the same question (0)
  • SyedHussain Profile Picture
    1,820 on at

    Which entity have you registered the plugin against?

  • Community Member Profile Picture
    on at

    Hi SYEDHUSSAIN,

    "new_Entity1" on creation of record in this entity a new record in "new_entity2" should be created..

  • Vijay Waghmare Profile Picture
    on at

    By looking at error desc, it seems plugin is not able to load correct version of assembly "Could not load file or assembly 'Microsoft.Xrm.Client, Version=6.0.0.0",

    Please refer right version of "Microsoft.Xrm.Client" dll in plugin to build & register plugin assembly to verify

    Thanks,

    Vijay Waghmare

  • Community Member Profile Picture
    on at

    So, VIJAY WAGHMARE,

    I need to try with the Latest SDK Version?...

    Thanks,

    Vijay

  • Suggested answer
    Vijay Waghmare Profile Picture
    on at

    yes, try with CRM 2013 SDK.

  • Community Member Profile Picture
    on at

    Thanks Vijay Waghmare,

    I've Tried with that one also.. but still showing the same error.

    Thanks,

    Vijay

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Launch!

Jump in, show your community spirit, and win prizes!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the May Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
ScottDurow Profile Picture

ScottDurow 2

#2
GJones Profile Picture

GJones 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans