"EF BB BF" at the beginning of JSON files created in Visual Studio

Viewed 19499

I have a bunch of JSON files set as Embedded resource in one of my projects. I'm using Newtonsoft.Json to parse these files:

public static string ReadStringFromStream(string streamName)
{
    using (System.IO.Stream stream = new EmbeddedResourceReader().GetType().Assembly.GetManifestResourceStream(streamName))
    {
        byte[] result = new byte[stream.Length];
        stream.Read(result, 0, (int)stream.Length);
        var str = Encoding.UTF8.GetString(result);
        return str;
    }
}
...

var traits = JsonConvert.DeserializeObject<Genre[]>(EmbeddedResourceReader.ReadStringFromStream("LNTCore.Genres.json"));
Genres = traits;

This throws an exception in Newtonsoft.Json because it can't parse the beginning of the file. What's the best practice in this case? How should I be handling this sort of situations?

Thanks!

2 Answers
Related