Error: An entry with the same key already exists. when parallel connect modem
Added by admin over 8 years ago
Hi admin,
I try to connect Parallel modem (For 10 usb at a time)
// Parallel
foreach (var modemInfo in arrModemPortAndDeviceID) {
Task.Factory.StartNew(
() => {
ScanCOMPortForModem(modemInfo.Port, modemInfo.DeviceID);
});
}
It throws Error: An entry with the same key already exists. Can you help me?
private IMobileGateway Connect(string portName)
{
MessageGateway<IMobileGateway, MobileGatewayConfiguration> messageGateway =
MessageGateway<IMobileGateway, MobileGatewayConfiguration>.NewInstance();
var config = MobileGatewayConfiguration.NewInstance();
config.PortName = portName;
config.BaudRate = PortBaudRate.BitsPerSecond115200; // TODO
config.DataBits = PortDataBits.Eight; // TODO
config.LicenseKey = LicenseKey;
config.DeleteReceivedMessage = true;
config.SafeConnect = true;
config.SafeDisconnect = true;
return messageGateway.Find(config);
}
Replies (3)
RE: Error: An entry with the same key already exists. when parallel connect modem - Added by admin over 8 years ago
Hi,
Do you have stack trace that you can provide?
Thanks
Regards
admin
RE: Error: An entry with the same key already exists. when parallel connect modem - Added by zl over 3 years ago
Hi,
I'm having the same problem as stated above. I'm using the latest library version from NuGet (1.8.3) on a x64 windows 10. I'm always getting the error "An entry with the same key already exists.":
System.ArgumentException HResult=0x80070057 Nachricht = Ein Eintrag mit dem gleichen Schlüssel ist bereits vorhanden. Quelle = System Stapelüberwachung: at System.Collections.Specialized.ListDictionary.Add(Object key, Object value) at MessagingToolkit.Core.Log.Logger.Init(LogProfile logprofile) at MessagingToolkit.Core.Log.Logger.UseSensibleDefaults(String logFileName, String logLocation, LogLevel logLevel, LogNameFormat logNameFormat) at MessagingToolkit.Core.Mobile.BaseMobileGateway`1.PerformSetup() at MessagingToolkit.Core.Mobile.MobileGatewayFactory.Find() at MessagingToolkit.Core.MessageGateway`2.Find(C config) at GatewayDiscoveryCmd.Program.GetGatewayInfo(String portName) in c:\users\felix\source\repos\GatewayDiscoveryCmd\GatewayDiscoveryCmd\Program.cs:line 68 at GatewayDiscoveryCmd.Program.<>c__DisplayClass1_0.<Main>b__0() in c:\users\felix\source\repos\GatewayDiscoveryCmd\GatewayDiscoveryCmd\Program.cs:line 31 at System.Threading.Tasks.Task`1.InnerInvoke() at System.Threading.Tasks.Task.Execute()
Here is sample exmple code (console application) to reproduce the issue.
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.IO.Ports;
using System.Threading;
using MessagingToolkit.Core;
using MessagingToolkit.Core.Mobile;
namespace GatewayDiscoveryCmd
{
class Program
{
public struct GatewayInfo
{
public String Port { get; set; }
public String DeviceModel { get; set; }
public String DeviceManufacturer { get; set; }
}
static void Main(string[] args)
{
string[] ports = SerialPort.GetPortNames();
List<Task<GatewayInfo>> discoveryTasks = new List<Task<GatewayInfo>>();
Console.WriteLine(String.Format("Scanning {0} ports ...", ports.Length));
foreach (string port in ports)
{
Task<GatewayInfo> task = Task<GatewayInfo>.Factory.StartNew(() => GetGatewayInfo(port));
discoveryTasks.Add(task);
}
Task.WaitAll(discoveryTasks.ToArray());
foreach (Task<GatewayInfo> task in discoveryTasks)
{
GatewayInfo gatewayInfo = task.Result;
Console.WriteLine(String.Format("Gateway at port {0} is model {1} by {2}", gatewayInfo.Port, gatewayInfo.DeviceModel, gatewayInfo.DeviceManufacturer));
}
}
private static GatewayInfo GetGatewayInfo(string portName)
{
// TODO Remove this statement if everything goes well, its only for debugging
Console.WriteLine("Task created at {0} on thread #{1}.", DateTime.Now.Ticks, Thread.CurrentThread.ManagedThreadId);
// Predefine the model and manufacturer
string deviceModel = "";
string deviceManufacturer = "";
MessageGateway<IMobileGateway, MobileGatewayConfiguration> messageGateway = MessageGateway<IMobileGateway, MobileGatewayConfiguration>.NewInstance();
MobileGatewayConfiguration mobileGatewayConfiguration = MobileGatewayConfiguration.NewInstance();
mobileGatewayConfiguration.GatewayId = portName;
mobileGatewayConfiguration.PortName = portName;
mobileGatewayConfiguration.BaudRate = PortBaudRate.BitsPerSecond115200;
mobileGatewayConfiguration.DataBits = PortDataBits.Eight;
mobileGatewayConfiguration.StopBits = PortStopBits.One;
mobileGatewayConfiguration.DtrEnable = true;
mobileGatewayConfiguration.RtsEnable = true;
mobileGatewayConfiguration.Parity = PortParity.None;
mobileGatewayConfiguration.Handshake = PortHandshake.None;
mobileGatewayConfiguration.DisablePinCheck = true;
// Find the mobile gateway according to the configuration
IMobileGateway mobileGateway = messageGateway.Find(mobileGatewayConfiguration);
if (null == mobileGateway)
{
throw new Exception("The mobile gateway could not be initialized! Please check the log files!");
}
// Get the device information
deviceModel = mobileGateway.DeviceInformation.Model;
deviceManufacturer = mobileGateway.DeviceInformation.Manufacturer;
// Disconnect the mobile gateway
mobileGateway.Disconnect();
mobileGateway.Dispose();
mobileGateway = null;
return new GatewayInfo { Port = portName, DeviceModel = deviceModel, DeviceManufacturer = deviceManufacturer };
}
}
}
RE: Error: An entry with the same key already exists. when parallel connect modem - Added by zl over 3 years ago
Crazy, seems to work after disabling the watchdog...