1

When submitting a large regular email campaign, it fails with the following exception:

ERROR Exception: System.NullReferenceException
Message: Object reference not set to an instance of an object.
Source: Sitecore.EmailCampaign
at Sitecore.Modules.EmailCampaign.Core.Dispatch.DispatchQueueItemDataReader.GetValue(Int32 i)
at System.Data.SqlClient.SqlBulkCopy.GetValueFromSourceRow(Int32 destRowIndex, Boolean& isSqlType, Boolean& isDataFeed, Boolean& isNull)
at System.Data.SqlClient.SqlBulkCopy.ReadWriteColumnValueAsync(Int32 col)
at System.Data.SqlClient.SqlBulkCopy.CopyColumnsAsync(Int32 col, TaskCompletionSource`1 source)
at System.Data.SqlClient.SqlBulkCopy.CopyRowsAsync(Int32 rowsSoFar, Int32 totalRows, CancellationToken cts, TaskCompletionSource`1 source)
at System.Data.SqlClient.SqlBulkCopy.CopyBatchesAsyncContinued(BulkCopySimpleResultSet internalResults, String updateBulkCommandText, CancellationToken cts, TaskCompletionSource`1 source)
at System.Data.SqlClient.SqlBulkCopy.CopyBatchesAsync(BulkCopySimpleResultSet internalResults, String updateBulkCommandText, CancellationToken cts, TaskCompletionSource`1 source)
at System.Data.SqlClient.SqlBulkCopy.WriteToServerInternalRestContinuedAsync(BulkCopySimpleResultSet internalResults, CancellationToken cts, TaskCompletionSource`1 source)
at System.Data.SqlClient.SqlBulkCopy.WriteToServerInternalRestAsync(CancellationToken cts, TaskCompletionSource`1 source)
at System.Data.SqlClient.SqlBulkCopy.WriteToServerInternalAsync(CancellationToken ctoken)
at System.Data.SqlClient.SqlBulkCopy.WriteRowSourceToServerAsync(Int32 columnCount, CancellationToken ctoken)
at System.Data.SqlClient.SqlBulkCopy.WriteToServer(IDataReader reader)
at Sitecore.Modules.EmailCampaign.Core.Data.SqlDbEcmDataProvider.AddToDispatchQueue(Guid messageId, MessageType messageType, IEnumerable`1 recipients, Dictionary`2 customPersonTokens, Dictionary`2 customQueryStringParameters)
at Sitecore.EmailCampaign.Cm.Dispatch.DispatchManager.Queue(Int32 threadIndex, IEntityBatchEnumerator`1 recipients, Int32 abTestRecipients, DispatchNewsletterArgs args, Int32 enqueueBatchSize)

Does anyone know the cause and steps to take to debug this issue?

1 Answer 1

1

Sitecore.EmailCampaign.Cm.Dispatch.DispatchManager.Queue is trying to queue all the applicable contacts in the list(s) that are selected when creating the email. This issue can occur if one or more contacts is missing the Alias identifier.

You can use the following code to find these contacts on the particular list and remove them from the list and log the result

var listId = Guid.Parse("74bd7b7d-1b54-48cd-ba3a-d67e16665eb7");

int batchSize = 200; // Size of the batch
string[] facets =
{
    CollectionModel.FacetKeys.PersonalInformation,
    CollectionModel.FacetKeys.ListSubscriptions,
    CollectionModel.FacetKeys.EmailAddressList
}; // Contact facets to retrieve
var contactListProvider = ServiceLocator.ServiceProvider.GetService<IContactListProvider>();
var contactProvider = ServiceLocator.ServiceProvider.GetService<IContactProvider>();
var subscriptionService = ServiceLocator.ServiceProvider.GetService<ISubscriptionService>();
var contactList = contactListProvider.Get(listId, System.Globalization.CultureInfo.InvariantCulture);
var contactBatchEnumerator = contactProvider.GetContactBatchEnumerator(
    contactList,
    batchSize,
        facets);
System.IO.File.AppendAllText(System.Web.Hosting.HostingEnvironment.MapPath("~/App_Data/InvalidEmail.csv"), $"ContactID,IdentifierSource,Identifier,PrimaryEmail" + Environment.NewLine);
while (contactBatchEnumerator.MoveNext())
{
    var contacts = contactBatchEnumerator.Current;

    try
    {
        foreach (var contact in contacts)
        {
            try
            {

                var email = contact.Emails()?.PreferredEmail?.SmtpAddress?.Trim()?.ToLower();
                var emailviaidentifier = contact.Identifiers.FirstOrDefault(x => x.Source == "email")?.Identifier?.Trim()?.ToLower();
                        
                if (!contact.Identifiers.Any(x => x.Source == "Alias"))
                {
                    Sitecore.Diagnostics.Log.Error($"ListCheck {contact.Id} no Alias", this);
                    System.IO.File.AppendAllText(System.Web.Hosting.HostingEnvironment.MapPath("~/App_Data/InvalidEmail.csv"), $"{contact.Id},email,{emailviaidentifier},{email}" + Environment.NewLine);
                    subscriptionService.Unsubscribe(listId, contact.Id.Value);
                }

            }
            catch (Exception ex)
            {
                Sitecore.Diagnostics.Log.Error($"ListCheck {contact.Id}", ex, this);
            }
        }
    }
    catch (Exception ex)
    {
        Sitecore.Diagnostics.Log.Error($"ListCheck", ex, this);
    }
}

Sitecore support have advised there is no supported way to programmatically add the Alias identifier and the best option is to manually delete and recreate these contacts.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.