Sitecore LinkDatabase throws System.FormatException: Unrecognized Guid format

Reason

This error seems to pop up when upgrading Sitecore. I ran into this in a solution after it was upgraded from Sitecore 7.2 to 7.5, and apparently the same issue araises when upgrading from 7.5 to Sitecore 8 (see this and that). The exception itself is thrown by the method Sitecore.Analytics.Data.TrackingField.ValidateLinks.

The following is my best guess as to what causes the issue: at some point in time, some of the Email Campaign Manager actions available in the __Tracking field changed names, IDs (e.g. “Form Submit Success” changed to “Form Submit”) or were removed.

Whether or not this change is handled by one of the many packages one has to install during an upgrade, I don’t know. Let’s assume that if you’re reading this, it’s too late to figure out if you’ve followed each step of the upgrade to the letter 😉

The solution for me was to:

  1. Find all items with broken links.
    PowerShell script run example
  2. Ensure “Standard Fields” are displayed in the Content Manager.
    Show standard fields
  3. Open a bugged item.
  4. Open the “Advanced” section and look for the “Tracking” field.
    Open tracking field attributes
  5. Click “Goals”. Click “Ok”.
  6. Click “Attributes”. Click “Ok”.
    Save tracking field values
  7. Repeat steps 3 – 6 for all affected items.

That’s it. The changes are saved automatically when clicking “Ok” and in my case all fields fixed themselves simply by opening and closing the tracking field dialog. If anyone knows of a way to automate steps 3 – 6 please let me know 🙂

If you keep getting errors, clearing the __Tracking field altogether and setting it up from scratch could be a last resort.

Code

Shown below are two ways to find items which cause a System.FormatException when rebuilding their links. Only items which contain a value in the __Tracking field are checked.

If you’re using Sitecore PowerShell Extensions, use the following script to find the broken items:

function HasBrokenLinks([Sitecore.Data.Items.Item] $item)
{
Try { [Sitecore.Globals]::LinkDatabase.UpdateReferences($item); return $false; }
Catch [System.FormatException] { return $true; }
}
$database = [Sitecore.Data.Database]::GetDatabase("master");
$suspects = $database.SelectItems("fast://*[@__Tracking != '']");
$suspects | Where-Object { HasBrokenLinks($_) } | Sort-Object Paths.Path | Format-Table ID, Name

If you’re not using Sitecore PowerShell Extensions the following form page can be used:

<%@ Page Language="C#" %>
<%@ Import Namespace="Sitecore" %>
<%@ Import Namespace="Sitecore.Data" %>
<%@ Import Namespace="Sitecore.Data.Items" %>
<%@ Import Namespace="Sitecore.Diagnostics" %>
<%@ Import Namespace="Sitecore.Links" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
  <title>Find broken tracking field links</title>
</head>
<body>
  <form runat="server">
    <asp:GridView runat="server" ID="Culprits" AutoGenerateColumns="False" ItemType="Sitecore.Data.Items.Item">
      <Columns>
        <asp:TemplateField HeaderText="ID">
          <ItemTemplate>
            <a href="/sitecore/shell/Applications/Content Manager/Default.aspx?fo=<%#Item.ID%>" target="_blank"><%#Item.ID%></a>
          </ItemTemplate>
        </asp:TemplateField>
        <asp:BoundField HeaderText="ID" DataField="ID" />
        <asp:BoundField HeaderText="Path" DataField="Paths.Path" />
      </Columns>
      <EmptyDataTemplate>
        <p>No broken tracking fields found.</p>
      </EmptyDataTemplate>
    </asp:GridView>
  </form>
</body>
</html>

<script runat="server">
  protected override void OnLoad(EventArgs e)
  {
    var database = Database.GetDatabase("master");
    var suspects = database.SelectItems("fast://*[@__Tracking != '']").OrderBy(item => item.Paths.Path).ToList();
    Culprits.DataSource = GetCulprits(suspects, Globals.LinkDatabase);
    DataBind();
  }

  private IEnumerable<Item> GetCulprits(IEnumerable<Item> suspects, LinkDatabase linkDatabase)
  {
    var culprits = new List<Item>();
    foreach (Item suspect in suspects)
    {
      try
      {
        linkDatabase.UpdateReferences(suspect);
      }
      catch (FormatException)
      {
        culprits.Add(suspect);
      }
    }
    return culprits;
  }
</script>

Example

Sample stacktrace (note Sitecore.Analytics.Data.TrackingField.ValidateLinks on line 7):

Job started: RebuildLinkDatabasesIndex|System.FormatException: Unrecognized Guid format.
  at System.Guid.GuidResult.SetFailure(ParseFailureKind failure, String failureMessageID, Object failureMessageFormatArgument, String failureArgumentName, Exception innerException)
  at System.Guid.TryParseGuid(String g, GuidStyles flags, GuidResult& result)
  at System.Guid..ctor(String g)
  at Sitecore.Analytics.Data.TrackingField.c__DisplayClass21.b__20(XElement e)
  at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
  at Sitecore.Analytics.Data.TrackingField.ValidateLinks(LinksValidationResult result)
  at Sitecore.Links.ItemLinks.AddLinks(Field field, List`1 links, ItemLinkState linkState)
  at Sitecore.Links.ItemLinks.GetLinks(ItemLinkState linkState, Boolean allVersions, Boolean includeStandardValuesLinks)
  at Sitecore.Links.LinkDatabase.UpdateReferences(Item item)
  at Sitecore.Links.LinkDatabase.RebuildItem(Item item)
  at Sitecore.Links.LinkDatabase.RebuildItem(Item item)
  at Sitecore.Links.LinkDatabase.RebuildItem(Item item)
  at Sitecore.Links.LinkDatabase.RebuildItem(Item item)
  at Sitecore.Links.LinkDatabase.RebuildItem(Item item)
  at Sitecore.Links.LinkDatabase.RebuildItem(Item item)
  at Sitecore.Links.LinkDatabase.Rebuild(Database database)
  at Sitecore.Shell.Applications.Dialogs.RebuildLinkDatabase.RebuildLinkDatabaseForm.Builder.Build()

8 thoughts on “Sitecore LinkDatabase throws System.FormatException: Unrecognized Guid format

  1. Powershell script also work with Sitecore 8.0. However if the script fixes the problem nothing is written to the console, so just rebuild link database afterwards.

  2. Pingback: Sitecore – RebuildSearchIndex|System.FormatException: Unrecognized Guid format. | Alan Coates – Sitecore/.NET blog

  3. I was having the same problem, indeed caused by the Web Forms module. Your solution worked great. Thank you very much for sharing!

  4. Thanks for your script, good job, keep it up.
    WFFM was the culprit, your script exposed the actual item behind it.

  5. Pingback: Sitecore. Unrecognized Guid format – Sitecore tackled

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s