Error logging multiple accounts from an application in c #

0

I know it's complicated to explain my problem is the following I found an open source program to authenticate accounts but it gives me an error:

Unhandled exception of type 'System.Collections.Generic.KeyNotFoundException' in mscorlib.dll

Additional information: The given key was not present in the dictionary.

The part of the code that marks when the fault occurs:

 #region Account Login: Single
            string AN = AccountTxt.Text;
            AnimationDisplay = string.Format("Logging In% | {0}", AN);
            AnimationTmr.Start();
            if (AN.Contains("@"))
            {
                Program.Emails[AN].BeginLogin(new AsyncCallback((iAr) =>
                {
                    HSession HS = (HSession)iAr.AsyncState;

                    if (HS.EndLogin(iAr))
                    {
                        Program.Accounts[HS.PlayerName] = HS;
                        Invoke(new Action(() =>
                        {
                            AccountTxt.Items.Remove(HS.Email);
                            AccountTxt.Items.Add(HS.PlayerName);
                            AccountTxt.SelectedIndex = AccountTxt.Items.IndexOf(HS.PlayerName);
                        }));
                        DisplayFinish("Login Success! | " + AN);
                    }
                    else
                        DisplayFinish("Login Failed! | " + AN);
                }), Program.Emails[AN]);
            }
            else
            {
                Program.Accounts[AN].BeginLogin(new AsyncCallback((iAr) =>
                {
                    DisplayFinish(string.Format("Login {0}! | {1}", (iAr.AsyncState as HSession).EndLogin(iAr) ? "Success" : "Failed", AN));
                }), Program.Accounts[AN]);
            }
            #endregion

What you want to say is that you include it in the dictionary but to what or more or less if you draw any conclusion comment me. I regret this annoyance again. If you need more code, I'll share it. I repeat the annoyance. And it's just that I want to log several accounts from c # but I need to know how to include them in the program.

  

Search all "program.emails", Subfolders, Keep modified files open, Search results 1, All the solution, ""     C: \ Users \ android \ Desktop \ K3ND4X-Silver 3d1tion \ Kendax-master \ Kendax \ Main.cs (59): if (HS! = Null &! Program.Emails.ContainsKey (HS.Email))     C: \ Users \ android \ Desktop \ K3ND4X-Silver 3d1tion \ Kendax-master \ Kendax \ Main.cs (61): Program.Emails [HS.Email] = HS;     C: \ Users \ android \ Desktop \ K3ND4X-Silver 3d1tion \ Kendax-master \ Kendax \ Main.cs (99): Program.Emails [Account] .BeginLogin (new AsyncCallback ((iAr) = >     C: \ Users \ android \ Desktop \ K3ND4X-Silver 3d1tion \ Kendax-master \ Kendax \ Main.cs (116):}), Program.Emails [Account]);     C: \ Users \ android \ Desktop \ K3ND4X-Silver 3d1tion \ Kendax-master \ Kendax \ Main.cs (140): Program.Emails [AN] .BeginLogin (new AsyncCallback ((iAr) = >     C: \ Users \ android \ Desktop \ K3ND4X-Silver 3d1tion \ Kendax-master \ Kendax \ Main.cs (156):}), Program.Emails [AN]);     Matching lines: 6 Matching files: 1 Files examined: 57     The search process has stopped.

    
asked by Perl 21.03.2016 в 21:54
source

1 answer

1

To validate and add a nonexistent key to the dictionary you could use

if(Program.Accounts.ContainsKey(HS.PlayerName))
    Program.Accounts[HS.PlayerName] = HS;
else
    Program.Accounts.Add(HS.PlayerName, HS);

Dictionary.ContainsKey Method (TKey)

    
answered by 21.03.2016 в 22:02