Sean Holmesby

.NET and Sitecore Developer

By

Serialization Exception in the Sitecore 8 Experience Explorer

I recently received a serialization exception when attempting trigger a Campaign within the new Experience Explorer feature in Sitecore 8, using the LaunchSitecore demo site.

Expecting state 'Element'.. Encountered 'Text' with name '', namespace ''.

[SerializationException: Expecting state 'Element'.. Encountered 'Text' with name '', namespace ''. ]
ReadArrayOfKeyValueOfstringstringFromJson(XmlReaderDelegator , XmlObjectSerializerReadContextComplexJson , XmlDictionaryString , XmlDictionaryString , CollectionDataContract ) +885
System.Runtime.Serialization.Json.JsonCollectionDataContract.ReadJsonValueCore(XmlReaderDelegator jsonReader, XmlObjectSerializerReadContextComplexJson context) +154
System.Runtime.Serialization.Json.JsonDataContract.ReadJsonValue(XmlReaderDelegator jsonReader, XmlObjectSerializerReadContextComplexJson context) +61
System.Runtime.Serialization.XmlObjectSerializerReadContext.InternalDeserialize(XmlReaderDelegator reader, String name, String ns, Type declaredType, DataContract& dataContract) +210
System.Runtime.Serialization.XmlObjectSerializerReadContext.InternalDeserialize(XmlReaderDelegator xmlReader, Type declaredType, DataContract dataContract, String name, String ns) +69
System.Runtime.Serialization.Json.DataContractJsonSerializer.InternalReadObject(XmlReaderDelegator xmlReader, Boolean verifyObjectName) +177
System.Runtime.Serialization.XmlObjectSerializer.ReadObjectHandleExceptions(XmlReaderDelegator reader, Boolean verifyObjectName, DataContractResolver dataContractResolver) +628
System.Runtime.Serialization.Json.DataContractJsonSerializer.ReadObject(XmlDictionaryReader reader) +73
Sitecore.Common.Serializer.Deserialize(String data, Type resultType) +541
Sitecore.Common.Serializer.Deserialize(String data) +89
Sitecore.SecurityModel.UserRuntimeSettings.DeserializeInnerDictionary(UserRuntimeSettings data, String dictionaryKey) +259
Sitecore.SecurityModel.UserRuntimeSettings.Deserialize(String data) +198
Sitecore.Security.Accounts.User.get_RuntimeSettings() +333

I also found the same issue when running my LaunchSitecoreTDS code base on a fresh instance…

Debugging this was difficult, as no exceptions were popping up in Visual Studio, and nothing useful was being written to the logs other that this exception.

Through the painful process of removing parts of code and testing about 50 times…I finally found the culprit.
The issue was to do with some code that accesses the current User Profile, and checks to see if they have anything in a Custom Property called ‘Favorites’.

While I couldn’t find the exact issue, I found that the Experience Explorer uses the user ‘sitecore\\eevirtualuser’.

I’ve now temporarily put a protecting statement around this block of code, checking for the eevirtualuser.

          List items = new List();
 
          Sitecore.Security.Accounts.User user = Sitecore.Context.User;
          if (user.Name == "sitecore\\eevirtualuser")
              return;
 
          Sitecore.Security.UserProfile profile = user.Profile;
          string ItemIds = profile.GetCustomProperty("Favorites");
 
          foreach (string itemId in ItemIds.Split('|'))
          {
          .
          .

I can now successfully run the Experience Explorer on the LaunchSitecore demo site.

A support ticket has been filed with Sitecore support to find a proper solution. This post will be updated once that ticket is addressed.

3 Responses to Serialization Exception in the Sitecore 8 Experience Explorer

  1. Pavel Veller says:

    Hi Sean,

    I have reported something very similar here – http://jockstothecore.com/sitecore-8-developers-notes-part-1/ – look for JSON serialization error. It’s been filed as issue #427759 and has been accepted as a defect in Sitecore 8. Here’s what the support team sent me back (haven’t had a chance to update my blog post just yet):

    1. Open the “\Website\sitecore\shell\client\Sitecore\ExperienceEditor\Commands\Save.js” file.
    2. Replace the following line in the “execute: function (context)” function:

    fields[postElements[i].id] = Sitecore.ExperienceEditor.Web.encodeHtml(postElements[i].value);

    With this line:

    fields[postElements[i].id] = Sitecore.ExperienceEditor.Web.encodeHtml(postElements[i].value.replace(/\\/g, ‘\\\\’));

    The ExperienceEditor JS is a new set of javascript that I haven’t really explored yet (I am very familiar with the PageMode JS and they are all still there but this is something new in 8). I haven’t looked at what they’re doing there with JSON serialization (and more importantly “why”) but your “\\” hinted me that it might very well be related.

    • sholmesby says:

      Hey Pavel,
      Thanks for your comment.
      I just followed these steps in a new Sitecore 8 instance with Launch Sitecore installed, but found it doesn’t fix the issue….so we possibly have run into different problems.
      The issue I see only appears within the Experience Explorer…not the Experience Editor… so I’m not sure if this code will still run there.

      We’ll see what Sitecore Support come back with.
      Thanks,
      Sean

  2. Pavel Veller says:

    You’re right. I looked closer at the stack trace and yours is something different. Also JSON but not what I reported. There’s a lot more JSON data in 8 with xDB and a lot more SPEAK apps (or SPEAK wrappers for old non-SPEAK apps – e.g. Experience Editor) and it gets trickier with proper escape sequences and matching “contracts” for ObjectJSONXML serialization. Eager to learn what you hear back form the support team.

Leave a Reply

Your email address will not be published. Required fields are marked *