My code:
Keys = new Dictionary<string, string>();
Keys.Add("Набег_0", "raid_0");
When I get Keys.ElementAt(0)
, I have this: {[Íàáåã_0, raid_0]}
.
Of course, when I run the program, key = "Набег_0"
is not defined and the program crashes with a System.Collections.Generic.KeyNotFoundException
This code worked fine when I had Windows 8.1 + Visual Studio 2013 + net 3.5
How do I fix this?
You somehow convinced the C# compiler that your source code was written in code page 1251, the default system code page in Eastern Europe and Russia. That's usually caused by the text file missing the utf-8 BOM. Unclear how this happened, maybe you created the file with a text editor other than the one built into Visual Studio. Maybe it got mangled by source control, the ones with a Unix background tend to drop the BOM.
Open the source file in Visual Studio and ensure it still reads correctly. Then use File > Save As, click the arrow on the Save button, select "with encoding" and pick "Unicode (UTF-8 with signature)".
Also make sure that the default is still good. File > Advanced Save Options > change the Encoding if necessary. If you habitually use another text editor then you'll want configure it so it saves files with a BOM.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With