November 1, 2019

Syncing TDS content with Sitecore and the Field Content Does Not Match Content-Length Error

By: Craig Taylor
November 1, 2019


Syncing TDS content with Sitecore and the Field Content Does Not Match Content-Length Error
So I recently ran into an issue on a new-to-me project.  The solution was already created, the project team had moved on to other projects and I was tasked with getting a new team ready to make some enhancements. While attempting to sync my Sitecore content with my local instance, I received a TDS error stating:

TDS Content Length Error


This is a known issue when working with TDS and git and the solution to correcting this has been provided earlier by others here and here.  In summary, the solution is to update the .gitattributes file by adding a line with the following:


This works great going forward, but doesn't address the issue you already have.  As both articles mention, the solution is to delete your local TDS files and re-sync.  For my situation, this doesn't work as I don't have the items in my local instance yet and deleting the items on disk would just lose them forever.

The solve is rather manual in nature, but here is what I did:

  1. Attempt to sync TDS with Sitecore and make note of all the items that have the error.  In my example, I'm only showing a single line, but you may have many. (as I did before I took this screenshot)

    TDS Sync View
  2. Open the .item file in a text editor.
  3. Take note of the template type of the item and create a new item in Sitecore with the same type. (making sure to create the item with the same name/path as in the item file)
  4. Copy the relevant fields from the .item file and paste them into the proper fields in your new Sitecore item.  In my case, I have an "Action" template item and only care about "Type", "Parameters" and "Security" fields. (Note: You don't have to worry about every field, but you should take care to bring over the important fields to your application.  You can usually ignore fields like "_sortorder", "__owner", "__created", etc.)

    Item View
  5. Save your Sitecore item.
  6. Sync your TDS item to Sitecore from Visual Studio.

Your error is now gone and you can continue on your way.  As mentioned, this can become an extremely tedious process depending on how many items and how many fields you have on your items, but in my case, was a necessary evil. Someone smarter than me could probably develop a script of some kind to address the error on a larger scale, but I'll leave that to the aforementioned smarter people.

References:

Deploying Sitecore Items with Git and TDS (Hans Léautaud from 2014): https://medium.com/sitecore-tips-tricks/deploying-sitecore-items-with-git-and-tds-f6a47605d1b4

Hedgehog TDS - Field Content Does Not Match Content-Length (Corey Smith from 2016): https://www.coreysmith.co/hedgehog-tds-field-content-does-not-match-content-length/

0 comments:

Post a Comment