Developer forum

Forum » Development » Error when sending out mails with same links

Error when sending out mails with same links

Anders Ebdrup
Reply

Hi,

 

I am using the Email marketing module to send out notify mails to users, when a product is on stock, but it is failing with this message:

[3/20/2015 2:02:57 PM]:    [3]: MergeAndDeliver failed. RecipientId: '13579'.

Logging 'Exception':
Type: System.ArgumentException
Message: An item with the same key has already been added.
StackTrace:    at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
   at Dynamicweb.EmailMessaging.MessagePreprocessor.HandleLinks(String content, Boolean isPreview) in E:\Program Files (x86)\Jenkins\jobs\Release DW841\workspace\Dynamicweb\EmailMessaging\MessagePreprocessor.vb:line 63
   at Dynamicweb.EmailMessaging.MessagingHandler.MessageHandler.MergeAndDeliverInternal() in E:\Program Files (x86)\Jenkins\jobs\Release DW841\workspace\Dynamicweb\EmailMessaging\MessagingHandler.vb:line 603
   at Dynamicweb.EmailMessaging.MessagingHandler.MessageHandler.MergeAndDeliver(RecipientQueueItem rqi) in E:\Program Files (x86)\Jenkins\jobs\Release DW841\workspace\Dynamicweb\EmailMessaging\MessagingHandler.vb:line 594
   at Dynamicweb.EmailMessaging.MessagingHandler.QueueWorker._Closure$__206._Closure$__207._Lambda$__834() in E:\Program Files (x86)\Jenkins\jobs\Release DW841\workspace\Dynamicweb\EmailMessaging\MessagingHandler.vb:line 458

Any help will be appreciated!

 

Best regards, Anders


Replies

 
Jeppe Eriksson Agger Dynamicweb Employee
Jeppe Eriksson Agger
Reply

Hi Anders,

This looks like the same issue we've been discussing for some time now. Have you tried the new version of Dynamicweb and cleaned the database that I mentioned in my last email? I didn't hear back from you, so I assumed all was well.

- Jeppe

 
Anders Ebdrup
Reply

Hi Jeppe,

 

Yes, and we still have the same problem...

Best regards, Anders

 
Anders Ebdrup
Reply

Hi Jeppe,

 

Do you need some more information from us to reproduce the problem??

 

Best regards, Anders

 
Anders Ebdrup
Reply

Can it be this part:

                    If existingLinks.ContainsKey(href) Then
                        link = existingLinks(href)

                        linksInUse.Add(link.OriginalUrl, link)
                        existingLinks.Remove(href)
                    ElseIf linksInUse.ContainsKey(href) Then

With linksInUse that is failing if I have two of the same links in my mail?

 

Best regards, Anders

 
Jeppe Eriksson Agger Dynamicweb Employee
Jeppe Eriksson Agger
Reply

Hi Anders,

There are two issues at play here where one leads to the other. The first issue is that multiple links to the same url are created -- this should not happen. This leads to the second issue which is the one you're actually seeing. In order to manage links for messages, the preprocessor keeps track of which links already exist and which links are new. We use the url as the key for tracking this, and because the first issue causes multiple links with the same url to be added, you get this "Key already added" exception.

The exception actually occurs before the code you mention is run. Specifically, it happens when the existingLinks dictionary is filled -- at least according to the stack trace from the exception you linked in the first post.

As I see it, the solution is to not add multiple links with the same url to the message, but reuse them as was originally intended. I implemented a synchronization of the logic that handles links so the message link collection can only be filled by one thread at a time. This should have eliminated the issue, if your data was cleaned/edited according to the email I sent you on 2015-02-13. Basically, it says to remove any links with the same LinkUrl from the OMCLink table so there's only one with that url per LinkReferenceKey. Then change the LinkClickLinkId for any rows that point to one of the removed links to the id of the one link that is left in the OMCLink table. After this, the table OMCLink should no longer have any rows that have the same LinkUrl value for the same LinkReferenceKey, and the OMCLinkClick rows have been updated to not point to any LinkId that no longer exists.

It's important to note that this clean-up does not happen automatically. You have to do it manually.

If I understand you correctly, you've already done this, and upgraded to the new build (8.4.1.29). If you have done the above mentioned clean-up, and upgraded to the new code, and it still fails, then I'd like a copy of the solution so I can see what's going on as I'm unable to reproduce it on my own solutions.

- Jeppe

 

You must be logged in to post in the forum