I have the TextFile1.txt with Hello, World! text in my C# project. The file is saved in UTF-8 encoding. It's file Build action property is Resource (not the Embedded resource).
Also I have some RESX-files with resources. I try to get string resources for each of them:
var asm = GetType().Assembly;
var name = $"{someType.FullName}.resources";
// var name = $"{asm.GetName().Name}.g.resources";
using (var stream = asm.GetManifestResourceStream(name))
using (var reader = new ResourceReader(stream)) {
reader.GetResourceData("textfile1.txt", out string resType, out byte[] bytes);
string text = Encoding.UTF8.GetString(bytes);
}
For different resources I get their values:
"\rHello, World!"
"�\u0016Command #1Command #1Command #1Command #1Command #1Command #1Command #1Command #1Command #1..."
"\rHello, World!"
"\r\0\0\0Hello, World!"
"@\v\0\0Command #2Command #2Command #2Command #2Command #2Command #2Command #2Command..."
The values contains garbage prefixes. The size of prefixes are not the same. I.e. I can't to skip the same size, for example bytes.Skip(sizeof(int)).ToArray() or bytes.Skip(sizeof(long)).ToArray(). Why the size of garbage prefixes are different and how can I trim it?