The problem is that "An item with the same key has already been added."
Every key is not unique in the data that you provided, because you use two dictionaries. I recommend against using "key" and "value" as your variable names, especially when you choose to use the following in one of your dictionaries: this.latinka.Add(value, key)
This can cause confusion because a dictionary add is <key, value>.
Solution: Your error occurs in this.latinka.Add(value, key)
. The variable "value" contains a value that already exists, which happens to be the key for this dictionary. Confused? This is why it is important to choose good variable names. The duplicate is "--..."
Modify your code as follows to see the error:
private void ReadDictionary(string filename)
{
string key = string.Empty;
string value = string.Empty;
string cesta = Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName);
try
{
string[] lines = File.ReadAllLines(filename, Encoding.Unicode);
if (lines != null)
{
}
foreach (string line in lines)
{
string[] znaky = line.Split('=');
key = znaky[0];
value = znaky[1];
try
{
this.morzeovka.Add(key, value);
}//try
catch (Exception ex)
{
string errMsg = "Error (morzeovka): " + ex.Message;
//errMsg += "(" + ex.StackTrace + ")";
errMsg += System.Environment.NewLine + System.Environment.NewLine;
errMsg += "morzeovka key: '" + key + "' morzeovka value: '" + value + "'";
MessageBox.Show(errMsg, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}//catch
try
{
this.latinka.Add(value, key);
}//try
catch (Exception ex)
{
string errMsg = "Error (latinka): " + ex.Message;
//errMsg += "(" + ex.StackTrace + ")";
errMsg += System.Environment.NewLine + System.Environment.NewLine;
errMsg += "latinka key: '" + value …