Loading TextAsset into Dictionary; duplicate key values not allowed

The following code gives the error “duplicate Key values not allowed”.

The values in the text file “Names” are definitely unique, so it has to be an issue with ToDictionary.

Can someone please point me to what I’m doing wrong, I’m new to lambda functions.

Dictionary<string, bool> langDictionary = new Dictionary<string, bool>();
char[] splitby = System.Environment.NewLine.ToCharArray();
var MytextAsset = Resources.Load ("Dictionaries/Names", typeof(TextAsset))  as TextAsset;
if (MytextAsset != null) {
    langDictionary = MytextAsset.text.Split (splitby).ToDictionary (s=>s,s=>true);
}

Thanks in advance.

If I was doing this I would just break it up a bit and see what’s going wrong.

i.e. split the string into tokens first, then iterate through them, adding to the dictionary one at a time to see where it fails.

Thanks for the help, managed to split the text asset to a simple string array and noticed it contained an empty entry for every line in the file.

Must have been double spaced. Anyway added StringSplitOptions.RemoveEmptyEntries to the split function and it all worked nicely