Search code examples
c#resourceswindows-services

How to read a resource file in C#


I have added a resource file to my project (C#, windows service - TopShelp):

enter image description here

I have added a text file to the resource:

enter image description here

Now I want to read the test file, this is what I have tried:

ResourceManager rm = new ResourceManager("My.Project.Name.Resources", Assembly.GetExecutingAssembly());

It does not find anything, ResourceSets count = 0.

Update

As suggested in the comments, I also tried adding the resource under:

Project > Properties > Resources

enter image description here

And tried the following code, which did not find anything:

ResourceManager rm = new ResourceManager("My.Project.Name.Resources", Assembly.GetExecutingAssembly());

Solution

  • Check your Resources.Designer.cs file. You should have there static string property named stop_words_utf8 (or whatever name for the file you choose). You use it like this:

    Resources.stop_words_utf8
    

    It is static string property