CodedUI test does not read data from CSV input file

Some text files start with a Byte Order Mark (BOM). The CSV reader within Coded UI does not handle the BOM and treats it as part of the first field name. The screen shot below shows the debug trace of a CSV file with a BOM and that same file shown in Notepad++. The DataRow.ItemArray[...] values are as expected. The DataRow.Table.Columns.ResultsView[...] shows the field names, but the first field name includes the BOM.

This CSV file with a BOM was created in Visual Studio using Solution Explorer => Add => New item => C# => General => Text file. Previously I have created a spread sheet with Microsoft Excel and saved it as a CSV file, that file did not have a BOM. I have also created files with Notepad++ and saved as CSV and they did not have a BOM. It appears that Visual Studio creates files with a BOM but when editing CSV files it does not add a BOM.

enter image description here


Visual Studio can create files with the correct encoding. Within “Step 2 – Create a data set” of this Microsoft page it states the text below. (Thanks also to Holistic Developer for providing very similar details in a comment.):

  1. It is important to save the .csv file using the correct encoding. On the FILE menu, choose Advanced Save Options and choose Unicode
    (UTF-8 without signature) – Codepage 65001 as the encoding.

Leave a Comment