Tag Archives: Microsoft Dynamics CRM

CRM 2011 Plugins – IServiceProvider

When a particular event occurs in Microsoft Dynamics CRM, such as “create of a contact” or “update of an account”, the Execute method is invoked for any plugins registered on the event. This method includes a single serviceProvider parameter which provides useful service information about the execution of the plugin. In this post, we will take a look at the information that is made available by the serviceProvider parameter.

The types of service objects available include the following:

  • IPluginExecutionContext
  • IOrganizationServiceFactory
  • ITracingService

The IPluginExecutionContext service object is the most useful of the three and provides contextual information to the plugin at run-time. It includes details about the user who triggered the plugin event as well as transactional information handled at the platform layer. The following code can be used to obtain the execution context from the service provider:

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

The IOrganizationServiceFactory service object allows us to create an instance of the organization service which can be used to define and execute various platform requests. The following code can be used to achieve this:

IOrganizationServiceFactory factory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
IOrganizationService sdk = factory.CreateOrganizationService(context.UserId);

In the example above, we pass in the GUID of the user who triggered the plugin event, which is obtained from the IPluginExecutionContext. Alternatively, we can pass in the GUID of another CRM user, or pass in a null value to execute the plugin logic under the system context.

Lastly, the ITracingService allows us to trace the plugin execution flow and any variables for debugging purposes. For more information, please read my post on Debugging Dynamics CRM 2011 Plugins.

There you have it, an introduction to the various service objects that we will be working with in our journey to create plugins for Microsoft Dynamics CRM. In my next post, we will take a closer look at the IPluginExecutionContext.

E-mail Router – An error occurred while processing the outgoing e-mail

I recently encountered an error with the Dynamics CRM 2011 E-mail Router where outgoing e-mail messages were stuck in a Pending state. The Event Viewer and E-mail Router trace file logged the following error:

03/05/2013 07:57:12 : #61042 – An error occurred while processing the outgoing e-mail message with subject “Some Photos” for SMTP: http://localhost:5555/crm for delivery through mail.roscode.com. System.Net.Mail.SmtpException: Failure sending mail. —> System.IndexOutOfRangeException: Index was outside the bounds of the array.
at System.Net.Base64Stream.EncodeBytes(Byte[] buffer, Int32 offset, Int32 count, Boolean dontDeferFinalBytes, Boolean shouldAppendSpaceToCRLF)
at System.Net.Base64Stream.Write(Byte[] buffer, Int32 offset, Int32 count)
at System.Net.Mime.MimePart.Send(BaseWriter writer)
at System.Net.Mime.MimeMultiPart.Send(BaseWriter writer)
at System.Net.Mail.SmtpClient.Send(MailMessage message)
— End of inner exception stack trace —
at System.Net.Mail.SmtpClient.Send(MailMessage message)
at Microsoft.Crm.Tools.Email.Providers.CrmPollingSendEmailProvider.Run()

I noticed that this error only occurs when the E-mail Router tries to send an e-mail which contains attachments. It turns out that this error is due to a bug with the .NET Framework where the System.Net.Mail.SmtpClient crashes when attempting to send e-mail messages with attachments larger than 3MB.

Microsoft has released a hotfix which you need to install on the server where the E-mail Router is installed. The hotfix can be found at http://support.microsoft.com/kb/2183292

CRM 2011 – Assembly must be registered in isolation

Here’s an interesting one! We recently used the Plugin Registration Tool to register a plug-in assembly with a Dynamics CRM 2011 on-premise deployment and received the following error:

Unhandled Exception: System.ServiceModel.FaultException`1[[Microsoft.Xrm.Sdk.OrganizationServiceFault, Microsoft.Xrm.Sdk, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]]: Action failed for assembly ‘Roscode.Plugins, Version=1.0.0.0, Culture=neutral, PublicKeyToken=d1d66274f9925088’: Assembly must be registered in isolation.
Detail:
-2147220906

Action failed for assembly ‘Roscode.Plugins, Version=1.0.0.0, Culture=neutral, PublicKeyToken=d1d66274f9925088’: Assembly must be registered in isolation.
2013-02-27T01:34:18.9471327Z

-2147220906

Action failed for assembly ‘Roscode.Plugins, Version=1.0.0.0, Culture=neutral, PublicKeyToken=d1d66274f9925088’: Assembly must be registered in isolation.
2013-02-27T01:34:18.9471327Z

Server stack trace:
at System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime operation, ProxyRpc& rpc)
at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)

Exception rethrown at [0]:
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
at Microsoft.Xrm.Sdk.IOrganizationService.Update(Entity entity)
at Microsoft.Xrm.Sdk.Client.OrganizationServiceProxy.UpdateCore(Entity entity)
at PluginRegistrationTool.RegistrationHelper.UpdateAssembly(CrmOrganization org, String pathToAssembly, CrmPluginAssembly assembly, PluginType[] type) in D:\Documents\CRM 2011 SDK\tools\pluginregistration\RegistrationHelper.cs:line 263
at PluginRegistrationTool.PluginRegistrationForm.btnRegister_Click(Object sender, EventArgs e) in D:\Documents\CRM 2011 SDK\tools\pluginregistration\PluginRegistrationForm.cs:line 382

Note that this error has nothing to do with registering the plug-in in isolation mode. It’s CRM’s funny way of telling you that you are not a Deployment Administrator. All you need to do is get another CRM administrator to add your user account to the list of Deployment Administrators within the Deployment Manager.

Hope this helps!

CRM 2011 E-mail Router – An error occurred while checking for e-mail messages to process in mailbox

We have configured the Microsoft Dynamics CRM 2011 E-mail Router for one of our clients who receive thousands of incoming e-mail messages to different mailboxes. As they rely on e-mail as their main source of communication, it is important that the E-mail Router can process incoming e-mail messages without any issues.

One of the issues we have seen recently is an error stating:

#27938 – An error occurred while checking for e-mail messages to process in mailbox me@mymailbox.com. System.NullReferenceException: Object reference not set to an instance of an object.
at Microsoft.Crm.Tools.Email.Providers.ExchangeWSConnector.RetrieveMessage(ArrayList ids, Int32 index, ServiceLogger serviceLogger)
at Microsoft.Crm.Tools.Email.Providers.ExchangePollingMailboxProvider.RetrieveNextMessageInternal()
at Microsoft.Crm.Tools.Email.Providers.CrmPollingMailboxProvider.RetrieveNextMessage()
at Microsoft.Crm.Tools.Email.Providers.CrmPollingMailboxProvider.Run()

This error occurs due to spam e-mail messages inside the mailbox. It is difficult to identify exactly which e-mails are causing issue but if you try to clear all spam, you will notice that the E-mail Router will continue to process incoming e-mail messages.

Dynamics CRM 2011 UR12 – Saving Records from Process Forms

Microsoft has completely redesigned some of the forms in Dynamics CRM 2011 update rollup 12 so that they are “process-driven”. The new design allows users to follow a step-by-step process to ensure that the right information is captured for different record types. One major change is the removal of the ribbon which has been replaced with a simplified menu. However, the new menu does not include the normal Save or Save and Close buttons, so how do I save my records?

Process-driven forms have an auto-save feature whereby the record is automatically saved each time a field is updated. Likewise the form is saved when you navigate away from the form (e.g. by clicking a link to a related record). Note that the auto-save does not take affect if the record is in create mode. There are no alerts and the form does not refresh, so it may not be obvious that the record is being saved.

Users can also force-save the form either by using the CTRL S shortcut key combination, or by clicking on the save icon which is tucked away in the bottom right-hand corner of the process form.

Image

Because of the “silent save”, it is important that you are careful with the changes you make to records via process forms in your CRM system.