Jean Paul's Blog

There are 2 types of People in the World, One who Likes SharePoint and..

  • Microsoft MVP

  • MindCracker MVP

  • CodeProject MVP

  • eBook on SharePoint 2010

  • eBook on Design Patterns

  • eBook on Windows Azure

  • NLayers Framework @ CodePlex

  • MSDN Forums

  • .Net vs. Java

    Due to Public Demand
  • Advertisements

Error :: XmlException was unhandled The ‘[‘ character, hexadecimal value 0x5B, cannot be included in a name. Line 1, position XXXXX

Posted by Paul on September 25, 2012

In this article I would like to update with a possible Error Scenario while working with the SPWebConfigModification class.


You are adding a new entry to the web.config file using SPWebConfigModification class.

SPWebService service = SPWebService.ContentService;

SPWebConfigModification modification = new SPWebConfigModification();




Unfortunately the following error is thrown repeatedly.

Error: XmlException was unhandled

The ‘[‘ character, hexadecimal value 0x5B, cannot be included in a name. Line 1, position XXXXX

Root Cause

Please note that the error might not be telling about the new modification. All the previous modifications are queued up and applied together to multiple farm servers. So you need to check all the modification entries for any problems with their Name, Value properties.

Additionally the character and position mentioned in the error message could be different.

You can locate the exact modification entry having problem using the following property.


This property should contain all the modifications. You can remove the wrong modification entry and use the Update() method to save the changes. Once the problem is fixed you can re-run your new modification code.

For example if you have the wrong entry at position 13, use the following code to remove the entry and update.



// You can also remove based on the Owner property.  Make sure you invoke the Update() method after making changes to the WebConfigModifications property.

Using Quick Watch

You can use the Quick Watch window to locate the problem entry.


Examine each item for the Name and Value property especially.

Additional Tip

You can always switch between different web applications using the following code.

SPWebService service = SPWebService.AdministrationService;


SPWebService service = SPWebService.ContentService;

Both the properties returns the SPWebService object associated with the name.



In this article we have explored a possible error scenario while working with SPWebConfigModification class.


Leave a Reply

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

You are commenting using your 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