0

I have done this thousands of times and cannot figure for the life of me why the StreamReader below is throwing this error. Running Visual Studios 2010 and .Net 4.0. Its old stuff but its never given me issues before.

var listOfEmailss = new List<string>();
         string emailFrom = email.Text.Trim();
        string pass = password.Text.Trim();
        StreamReader tr = new StreamReader(@"â€ĒC:\Users\Tom\Desktop\emailTest.txt");
        string line = "";
        while ((line = tr.ReadLine()) != null)
        {
            listOfEmailss.Add(line.Split(',').Last().Trim());
        }

enter image description here

user2755680
  • 85
  • 11
  • Check that you don't have any hidden characters or codepoints in the path string. I've sometimes had some that don't show in the editor but cause issues – Sami Kuhmonen Oct 28 '16 at 04:03

3 Answers3

2

This answer suggests that there might be hidden unicode characters in your string. Delete it and re-type it manually.

Community
  • 1
  • 1
apk
  • 1,550
  • 1
  • 20
  • 28
  • I must have missed that link. However, I don't see an actual solution to remove those character literals. Is manually retyping everything the only option? No way to remove them in code. – user2755680 Oct 28 '16 at 04:14
  • You have to manually re-type the string literal. You could probably sanitize it using code, but given that the problem is with the *source*, you should probably fix it there. – apk Oct 28 '16 at 04:30
1

This is annoying isn't it. I have faced it in the past. If you have copied the path from Windows explorer or somewhere else chances are there is a hidden character that has come in into the path string. I would recommend that you explicitly delete the file path and type it manually.

That should sort it.

To confirm copy the same path (what you have right now) and try and create a FIleInfo object. My guess is that you will face the same exception there too.

Nikhil
  • 3,304
  • 1
  • 25
  • 42
1

The issue is that there is a unicode character embedded in the file path. Specifically, there is a "left-to-right embedding" character right after the between the quotation mark and c at the very beginning.

I would delete those characters and retype them.

Paul Tsai
  • 893
  • 6
  • 16