[CRM Online] Avoid attachments using a plugin and weird exception messages: The specified domain does not exist or cannot be contacted. An unexpected error occurred from ISV code

Writing a simple plugin to avoid attachments in Dynamics CRM Online, I have seen weird exceptions messages.

Note: Using Dynamics CRM 2011 Developer Toolkit from CRM 2011 SDK

Find all the code of this example and the CRM solution here

Initially, this is the code of the plugin linked to “annotation” in the Create and Update events (shown just the execute method):


Now, let’s try to attach a new file:


In this case, where an unknown error will happen, I could expect a message similar to this:


Notice I would be able to retrieve traces and see more information.

However, instead of that message, I am getting this other weird error without any trace or useful information: “The specified domain does not exist or cannot be contacted. An unexpected error occurred from ISV code”


To improve this message, I have had to add a try-catch, encapsulate that unexpected exception and throw an InvalidPluginExecutionException:


And now I get the next message:


As you can see, this message is a bit more friendly, but it is not yet the usual desired message we would like seeing with traces, something like this:




Exception messages in attachments for the annotation entity seem to behave differently compare to what we have seen in other entities. Use InvalidPluginExecutionException correctly to guarantee the best result.

Other advices/ideas:

If you are using CRM 2011 Developer Toolkit, Plugins inherit from Plugin class. You can improve the error handling in this base class and customise the traces and error logs in the way you better want.

About Ramon Tebar

Software Engineer specialised on Microsoft Technologies with experience in large projects for different industrial sectors as developer, consultant and architect. I enjoy designing and developing software applications, it is my job and one of my hobbies. I’m interested in design patterns, new technologies and best practices. Making those part of the ALM process is a great challenge. During the last years, I have specialised in Microsoft Dynamics CRM (now Dynamics 365). I customise and extend the platform to provide tailored solutions and integrations based on service-oriented architectures and messages queuing. Motivated by community events and contributor in blogs, technical books, open source projects and forums, I have been awarded Microsoft Most Valuable Professional (MVP) on Dynamics 365 (CRM) since 2012.

Posted on May 11, 2013, in CRM, CRM Online and tagged . Bookmark the permalink. Leave a comment.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: