Author Topic: System.ArgumentException: An item with the same key has already been added.  (Read 1163 times)

TheColonel26

  • Newbie
  • *
  • Posts: 25
    • View Profile
After upgrading to 3.99y, I am receiving this exception when calling on an address that already has one subscription. I am doing this on purpose as I have 2 different threads that share the same FINS comm object. This only happens in Mono. my current system is Debian 9.5 x64. I have tired Mono Version 4.6.2 and Mono Version 5.14.0

so if I call

_FINsCom.Subscribe("W506",1,100, a.DataReceived);
_FINsCom.Subscribe("W506",1,100, b.DataReceived); // I get an exception of System.ArgumentException: An item with the same key has already been added.

when I ran it in 5.14.0 I got the same error except "Key of 0" was tacked on to the end

stack trace is attached

EDIT:

I take that back, it is happening on the first subscription and seems to have nothing to do with multiple subscriptions.

have you used VSMonoDebugger https://github.com/GordianDotNet/VSMonoDebugger? That is what I am using for debugging my application on Mono. See My X-Server Support Issue to get X-Server support working. https://github.com/GordianDotNet/VSMonoDebugger/issues/3

I have no idea why this is happening all of a sudden, it seemed to be working fine before. I even removed all of the AHMI Projects out of my Solution, deleted them and re added them. No change.

EDIT2: I ended up doing this as a workaround, it succeeds on the second try
Code: [Select]

            int retries = 2;
            for (int i = 0; i <= retries; i++)
            {
                try
                {
                    _FINsCom.Subscribe(address, numberOfElements, pollrate, tempAS.InternalDataReceived);
                    break;
                }
                catch (ArgumentException ex) when (ex.Message.Contains("key"))
                {
                    if(i == retries)
                    {
                        Logger?.Error(ex, "AHMI Error encountered while subscribing to {Address}. Retry Limit of {retries} Has been reached", address, i, retries);
                        throw;
                    }
                    else
                    {
                        Logger?.Error(ex, "AHMI Error encountered while subscribing to {Address}. Retry {retry} of {retries}", address, i, retries);
                    }
            }
« Last Edit: September 21, 2018, 11:54:01 AM by TheColonel26 »