Tuesday 24 September 2013

On press of Find Available time on Schedule service activity CRM throws "An Unexpected error occurred." error

 
On press of Find Available time on Schedule service activity CRM throws "An Unexpected error occurred." error
 
In event viewer the following error message is shown
 
The Web Service plug-in failed in OrganizationId: xxxxx-xxxx-xxxx-xxxxxxxxxxx; SdkMessageProcessingStepId: xxxxxx-xxxx-xxxx-xxxx-xxxxxxxxx; EntityName: none; Stage: 30; MessageName: Search; AssemblyName: Microsoft.Crm.Extensibility.InternalOperationPlugin, Microsoft.Crm.ObjectModel, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35; ClassName: Microsoft.Crm.Extensibility.InternalOperationPlugin; Exception: Unhandled Exception: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
   at System.RuntimeMethodHandle._InvokeMethodFast(IRuntimeMethodInfo method, Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeType typeOwner)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at System.Web.Services.Protocols.LogicalMethodInfo.Invoke(Object target, Object[] values)
   at Microsoft.Crm.Extensibility.InternalOperationPlugin.Execute(IServiceProvider serviceProvider)
   at Microsoft.Crm.Extensibility.V5PluginProxyStep.ExecuteInternal(PipelineExecutionContext context)
   at Microsoft.Crm.Extensibility.VersionedPluginProxyStepBase.Execute(PipelineExecutionContext context)
Inner Exception: System.ArgumentException: Item has already been added. Key in dictionary: 'Plugin Friendly Name'  Key being added: 'Plugin Friendly Name'
   at System.Collections.Hashtable.Insert(Object key, Object nvalue, Boolean add)
   at Microsoft.Crm.Scheduling.Engine.PluginTypeLibrary.LoadPlugins(SchedulingContext context)
   at Microsoft.Crm.Scheduling.Engine.PluginTypeLibrary.GetPluginType(String friendlyName, SchedulingContext context)
   at Microsoft.Crm.Scheduling.UserDefinedFunctionFactory.Create(IPluginTypeLibrary typeLibrary, String functionName, SchedulingContext context)
   at Microsoft.Crm.Scheduling.UdfExpression.Evaluate(SchedulingContext context, Object[] args)
   at Microsoft.Crm.Scheduling.Engine.ResourceSpecTree.EvaluateObjective(IExpression expression, IResource resource, DateTime proposalStartTime, TraceInfo traceInfo, AppointmentRequest request, Int32 leftOffset, Int32 rightOffset, SchedulingContext context)
   at Microsoft.Crm.Scheduling.Engine.ResourceSpecTree.ScoreTreeContext(NodeEntry bindEntry, TimeInterval interval, AppointmentRequest request, TraceInfo traceInfo, TimeZone userTimeZone, SchedulingContext context)
   at Microsoft.Crm.Scheduling.Engine.Strategy.Search(AppointmentRequest request, SchedulingContext schedulingContext)
   at Microsoft.Crm.Scheduling.Engine.StrategyBroker.Search(AppointmentRequest request, SchedulingContext context)
   at Microsoft.Crm.Scheduling.ScheduleSearchCommand.Execute(ISchedulingExecutionContext context)
   at Microsoft.Crm.ObjectModel.ScheduleService.Search(AppointmentRequest request, ExecutionContext context)
 
 
This is happening due to CRM is adding plugin name in some sort of dictionary and in the system it is finding plugins with the same Friendly name. The name of plugin is in  the following lines copied from above
 
Inner Exception: System.ArgumentException: Item has already been added. Key in dictionary: 'Plugin Friendly Name'  Key being added: 'Plugin Friendly Name'
 
Though the plugins are coming from totally different solutions and have there own namespace still due to we using crm developer toolkit the friendly name generated does not contains the complete name space and due to this there are duplicate friendly name exists in the system and somehow CRM scheduling engine is adding the plugin friendly names in dictionary and hence giving error.
 
Resolution is to update the plugin friendly name and make sure these are unique with in system they are going to be exported if not sure then make the friendly name include the name space of the project.

Thursday 12 September 2013

sending CRM email with just the email address only

Entity toParty = new Entity("activityparty");
toParty["addressused"] =" khan.kaleemul@gmail.com"

Entity email = new Entity("email");
email["from"]=new Entity[]{ <<from party>>};

email["to"]= new Entity[]{toParty};
email["subject"]="email subject";
email["description"]="email body";
email["regardingobjectid"]=<<"regarding entity">>;

Guid emailId = crmService.Create(email);

SendEmailRequest reqSendEmail = new SendEmailRequest();
reqSendEamil = emailId;
reSendEmail.TrackingToken = string.empty;
reqSendEmail.IssueSend = true;

crmService.Execute(reqSendEmail);