Question

I've noticed that GitHub for windows, reports some files changed that I think should not have. The issue arrises with some .txt-files that are read in our application. After running the program, all the read .txt's are reported to have every line ending doubled: E.g:

Line1
Line2

becomes

Line1

Line2

I had a feeling that this was do to some line ending issue, and maybe a wrong setting in git, so I looked at it Notepad++ showing all characters. Before running the program the files look like this:

Line1   CRLF
Line2   CRLF
Line3

And after, they become:

Line1   CR
CRLF
Line2   CR
CRLF
Line3

So it seems GH4W is correct in reporting them changed. The trouble is, they shouldn't be. I'm reading them with a StreamReader like this:

// ASCII.RodBarcodes holds path to RodBarcodes.txt
using (StreamReader sr = new StreamReader(ASCII.RodBarcodes))
        {
            int count = 0;
            string line = sr.ReadLine();
            while (line != null)
            {
                Rods.Add(new AnemometerRod());
                Rods[count].Barcode = line;
                line = sr.ReadLine();
                count++;
            }
        }

Where are these extra CR coming from?

Was it helpful?

Solution

Since this question reasently got an upvote, I guess I'd better answer it, myself.

The issue had nothing to do with StreamReader (of course). What was in fact happening, was that the program auto-updated the files from a network-share (I had taken over a project from someone else), where the line endings were a mess. Fixing that at the source fixed this issue.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top