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??