I would post my code, but I don’t see the point, since if I put a breakpoint in it, it never reaches it, the error is triggered before the execution reaches it. I initially thought it could have been a duplicate in the .config file, but I haven’t seen any. The code compiles properly.
Thanks.
Here is the error I get:
Unhandled Exception: System.ArgumentException: An item with the same key has alr
eady been added.
at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)
at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boo
lean add)
at System.Collections.ObjectModel.KeyedCollection`2.AddKey(TKey key, TItem it
em)
at System.Collections.ObjectModel.KeyedCollection`2.InsertItem(Int32 index, T
Item item)
at NDesk.Options.OptionSet.InsertItem(Int32 index, Option item)
at System.Collections.ObjectModel.Collection`1.Add(T item)
at NDesk.Options.OptionSet.Add(String prototype, String description, Action`1
action)
at manifest_mass_deployment.Program.Main(String[] args)
Edit: The error was related to NDESK, I was using the same variable twice:
var p = new OptionSet(){
{ "t|time=", "start time", v=> starttime = v },
{ "s|span=", "span time", v=> spantime = v },
{ "t|thread=", "Fhreads to fork", v=> threads = v },
}
The problem arises with
NDesk. If this is the callback-based program option parser for C# found here, maybe it does something before your code runs? Maybe it tries to parse command line options?At least, the message is clear:
NDeskis trying to add a key to a dictionary which already exists. If this is nothing in your code, it must be some automatic mechanism that for example reads a file and builds a dictionary from it.From what I see,
NDeskshould help you parse command line options – the problem may be that you’re passing in the same parameter twice?