The xml passed to the platform is not well-formed xml

Today while executing a plugin that has a method that search for a record of a custom entity based on its name, I started to see the following error:

Untitled picture

Once I debugged the plugin, I found that the string I was using to search based on the name had an apostrophe(‘) and this was messing up with the Fetch XML apostrophes.

Solution

To correctly escape the special characters in the name I added the following regex line:

string FormatedText = Regex.Escape(RecordName);

This will add the correct c# scape to each of the special characters, for example, instead of having apostrophe (‘) it will be replaced with: \’

Hope it helps.

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