Hey Corey,
exception is throwing from Identify method from class : Sitecore.Analytics.Tracking.StandardSession
I can see is trying to load a contact but the result is not a successfully
LockAttemptResult<Contact> result = manager.TryLoadContact(contactId);
is checking if result is
LockAttemptStatus.Success
and if is not success then is throwing the error.
Can you check if you have contact with that id ?
Please check bellow code to understand more why is happening. I hope my tips will help you a little bit.
public override void Identify(string userName)
{
Assert.ArgumentNotNull(userName, "userName");
Assert.IsNotNull(this.Contact, "this.Contact should not be null");
Assert.IsNotNull(this.Interaction, "this.Interaction should not be null");
Assert.IsNotNull(this.Device, "this.Device should not be null");
ContactManager manager = Factory.CreateObject("tracking/contactManager", true) as ContactManager;
ContactRepositoryBase base2 = Factory.CreateObject("contactRepository", true) as ContactRepositoryBase;
Assert.IsNotNull(base2, "contactRepository");
Contact contact = base2.LoadContactReadOnly(userName);
if ((contact == null) || (contact.ContactId == Guid.Empty))
{
bool flag = false;
if (this.Contact.Identifiers.IdentificationLevel != ContactIdentificationLevel.Known)
{
if (((this.Contact.ContactSaveMode != ContactSaveMode.NeverSave) && !this.Settings.IsTransient) && (ContactClassification.IsHuman(this.Contact.System.Classification) || ContactClassification.IsAutoDetectedRobot(this.Contact.System.Classification)))
{
if (this.Contact.System.VisitCount > 1)
{
contact = base2.LoadContactReadOnly(this.Contact.ContactId);
}
if (contact == null)
{
contact = base2.CreateContact(this.Contact.ContactId);
contact.IsTemporaryInstance = true;
}
flag = true;
}
else
{
contact = this.Contact;
}
}
else
{
flag = true;
ID id = string.Equals(this.Contact.Identifiers.Identifier, userName, StringComparison.InvariantCultureIgnoreCase) ? this.Contact.ContactId.ToID() : ID.NewID;
contact = base2.CreateContact(id);
}
contact.Identifiers.IdentificationLevel = ContactIdentificationLevel.Known;
contact.Identifiers.Identifier = userName;
if (flag)
{
manager.FlushContactToXdb(contact);
}
}
if (this.Contact.ContactId == contact.ContactId)
{
if (ContactClassification.IsAutoDetectedRobot(this.Contact.System.Classification))
{
this.SetClassification(0, this.Contact.System.OverrideClassification, true);
}
this.Contact.Identifiers.IdentificationLevel = ContactIdentificationLevel.Known;
this.Contact.Identifiers.Identifier = userName;
Log.Debug("StandardSession.Identify - contact is already loaded: " + this.Contact.ContactId);
}
else
{
Guid contactId = contact.ContactId;
LockAttemptResult<Contact> result = manager.TryLoadContact(contactId);
if ((result.Status == LockAttemptStatus.AlreadyLocked) && (result.LockedBy.Type == LeaseOwnerType.WebCluster))
{
Log.Debug("StandardSession.Identify - contact is locked, transferring: " + contactId);
TransferSessionPipeline.Run(new TransferSessionArgs(new Guid?(contactId), this, result.LockedBy.Identifier, HttpContext.Current.Request.Url));
}
else
{
if (result.Status != LockAttemptStatus.Success)
{
throw new ContactLockException(string.Format("Contact {0} could not be locked in the XDB.", contactId));
}
if (this.Contact.Identifiers.IdentificationLevel != ContactIdentificationLevel.Known)
{
Contact dyingContact = this.Contact;
this.Contact = result.Object;
base2.MergeContacts(this.Contact, dyingContact);
manager.ReleaseContact(dyingContact.ContactId);
manager.RemoveFromSession(dyingContact.ContactId);
this.Interaction.ContactId = this.Contact.ContactId;
this.Interaction.ContactVisitIndex = this.Contact.System.VisitCount;
Log.Debug("StandardSession.Identify - merged: " + this.Contact.ContactId);
}
else
{
this.Interaction.AcceptModifications();
Guid channelId = this.Interaction.ChannelId;
CommitSessionPipelineArgs args = new CommitSessionPipelineArgs {
Session = this
};
CommitSessionPipeline.Run(args);
this.Contact = result.Object;
ICurrentPageContext currentPage = this.Interaction.CurrentPage;
HttpContextWrapper httpContext = new HttpContextWrapper(HttpContext.Current);
this.CreateInteraction(httpContext);
Assert.IsNotNull(this.Device, "StandardSession.Device is null.");
Assert.IsNotNull(this.Interaction, "StandardSession.Interaction is null.");
this.Interaction.DeviceId = this.Device.DeviceId;
this.Interaction.ChannelId = channelId;
this.Interaction.CreatePage();
this.InitializePage(this.Interaction.CurrentPage, currentPage);
Assert.IsNotNull(this.Contact, "StandardSession.Contact is null.");
Log.Debug("StandardSession.Identify - started new logical visit: " + this.Contact.ContactId);
}
this.Device.LastKnownContactId = new Guid?(this.Contact.ContactId);
}
}
}
public override void Identify(string userName)
{
Assert.ArgumentNotNull(userName, "userName");
Assert.IsNotNull(this.Contact, "this.Contact should not be null");
Assert.IsNotNull(this.Interaction, "this.Interaction should not be null");
Assert.IsNotNull(this.Device, "this.Device should not be null");
ContactManager manager = Factory.CreateObject("tracking/contactManager", true) as ContactManager;
ContactRepositoryBase base2 = Factory.CreateObject("contactRepository", true) as ContactRepositoryBase;
Assert.IsNotNull(base2, "contactRepository");
Contact contact = base2.LoadContactReadOnly(userName);
if ((contact == null) || (contact.ContactId == Guid.Empty))
{
bool flag = false;
if (this.Contact.Identifiers.IdentificationLevel != ContactIdentificationLevel.Known)
{
if (((this.Contact.ContactSaveMode != ContactSaveMode.NeverSave) && !this.Settings.IsTransient) && (ContactClassification.IsHuman(this.Contact.System.Classification) || ContactClassification.IsAutoDetectedRobot(this.Contact.System.Classification)))
{
if (this.Contact.System.VisitCount > 1)
{
contact = base2.LoadContactReadOnly(this.Contact.ContactId);
}
if (contact == null)
{
contact = base2.CreateContact(this.Contact.ContactId);
contact.IsTemporaryInstance = true;
}
flag = true;
}
else
{
contact = this.Contact;
}
}
else
{
flag = true;
ID id = string.Equals(this.Contact.Identifiers.Identifier, userName, StringComparison.InvariantCultureIgnoreCase) ? this.Contact.ContactId.ToID() : ID.NewID;
contact = base2.CreateContact(id);
}
contact.Identifiers.IdentificationLevel = ContactIdentificationLevel.Known;
contact.Identifiers.Identifier = userName;
if (flag)
{
manager.FlushContactToXdb(contact);
}
}
if (this.Contact.ContactId == contact.ContactId)
{
if (ContactClassification.IsAutoDetectedRobot(this.Contact.System.Classification))
{
this.SetClassification(0, this.Contact.System.OverrideClassification, true);
}
this.Contact.Identifiers.IdentificationLevel = ContactIdentificationLevel.Known;
this.Contact.Identifiers.Identifier = userName;
Log.Debug("StandardSession.Identify - contact is already loaded: " + this.Contact.ContactId);
}
else
{
Guid contactId = contact.ContactId;
LockAttemptResult<Contact> result = manager.TryLoadContact(contactId);
if ((result.Status == LockAttemptStatus.AlreadyLocked) && (result.LockedBy.Type == LeaseOwnerType.WebCluster))
{
Log.Debug("StandardSession.Identify - contact is locked, transferring: " + contactId);
TransferSessionPipeline.Run(new TransferSessionArgs(new Guid?(contactId), this, result.LockedBy.Identifier, HttpContext.Current.Request.Url));
}
else
{
if (result.Status != LockAttemptStatus.Success)
{
throw new ContactLockException(string.Format("Contact {0} could not be locked in the XDB.", contactId));
}
if (this.Contact.Identifiers.IdentificationLevel != ContactIdentificationLevel.Known)
{
Contact dyingContact = this.Contact;
this.Contact = result.Object;
base2.MergeContacts(this.Contact, dyingContact);
manager.ReleaseContact(dyingContact.ContactId);
manager.RemoveFromSession(dyingContact.ContactId);
this.Interaction.ContactId = this.Contact.ContactId;
this.Interaction.ContactVisitIndex = this.Contact.System.VisitCount;
Log.Debug("StandardSession.Identify - merged: " + this.Contact.ContactId);
}
else
{
this.Interaction.AcceptModifications();
Guid channelId = this.Interaction.ChannelId;
CommitSessionPipelineArgs args = new CommitSessionPipelineArgs {
Session = this
};
CommitSessionPipeline.Run(args);
this.Contact = result.Object;
ICurrentPageContext currentPage = this.Interaction.CurrentPage;
HttpContextWrapper httpContext = new HttpContextWrapper(HttpContext.Current);
this.CreateInteraction(httpContext);
Assert.IsNotNull(this.Device, "StandardSession.Device is null.");
Assert.IsNotNull(this.Interaction, "StandardSession.Interaction is null.");
this.Interaction.DeviceId = this.Device.DeviceId;
this.Interaction.ChannelId = channelId;
this.Interaction.CreatePage();
this.InitializePage(this.Interaction.CurrentPage, currentPage);
Assert.IsNotNull(this.Contact, "StandardSession.Contact is null.");
Log.Debug("StandardSession.Identify - started new logical visit: " + this.Contact.ContactId);
}
this.Device.LastKnownContactId = new Guid?(this.Contact.ContactId);
}
}
}