"The given key was not present" error

Jan 15, 2015 at 2:59 PM
Edited Jan 15, 2015 at 3:00 PM
HI there,

I would like your help please.

I've created an IVR script on a webserver. It keeps failing randomly. To find out the issue, I wrote a CurrentDomain_UnhandledException. It prints out a message and the source of the error.

It gave this error.
The given key was not present in the dictionary. 

System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary.
   at AsterNET.FastAGI.AGIConnectionHandler.Run() in e:\Projects\Codeplex\AsterNET\Asterisk.2013\Asterisk.NET\FastAGI\AGIConnectionHandler.cs:line 103
   at AsterNET.Util.ThreadTask.Run() in e:\Projects\Codeplex\AsterNET\Asterisk.2013\Asterisk.NET\Util\ThreadTask.cs:line 36
   at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.ThreadHelper.ThreadStart()
This is how I configured the agiServer component before starting it.
int PortNumber = ToolboxHelper.getSettingByNameAsInt("PortNumber");

            AsteriskFastAGI agiServer=new AsteriskFastAGI
            {
                MappingStrategy = new GeneralMappingStrategy(
                    new List<ScriptMapping>()
                    {
                        new ScriptMapping()
                        {
                            ScriptName = "callmonitor", // script name - passed by the Asterisk server
                            ScriptClass = "AsteriskAGI.CallMonitorAGI" // code to run for this script
                        }
                    })
            };

            agiServer.BindPort = PortNumber;

           try
            {
                agiServer.Start(); // Start the service. This runs synchronously - ctrl+c to exit
                
            }
            catch (Exception ex)
            {

            }
This error is occuring in the AsterNET code.

What's happening in AGIConnectionHandler.cs at line 103? What key is it expecting? This happens randomly, perhaps also when a call has connected with my script.

Am I missing something in my setup?
Jan 15, 2015 at 3:12 PM
Edited Jan 15, 2015 at 3:37 PM
I had a look at the ThreadTask on line 36 code here at codeplex.
public override void Run()
        {
            while (true)
            {
                AGIConnectionHandler job = ThreadPool.obtainJob(); // may have broken process here
                if (job == null)
                    break;
                job.Run();
            }
        }
I also looked at the code.
internal AGIConnectionHandler obtainJob()
        {
            AGIConnectionHandler job = null;
            lock (jobs)
            {
                while (job == null && running)
                {
                    try
                    {
                        if (jobs.Count == 0)
                            Monitor.Wait(jobs);
                    }
                    catch (ThreadInterruptedException ex)
                    {
#if LOGGER
                        logger.Error("System.Threading.ThreadInterruptedException.", ex);
#else
                        throw ex;
#endif
                    }
                    if (jobs.Count > 0)
                    {
                        job = jobs[0];
                        jobs.RemoveAt(0);
                    }
                }
            }

            if (running)
                return job;
            else
                return null;
        }
Is it breaking because it cannot find one of the jobs by index? i.e. dictionary/list.