Getting values from my resource after publishing.

Maor kam 21 Reputation points


I want to get a value from my resx file.

In my project, I use 2 approaches to get the value:


ResourceManager resourceManager = new ResourceManager("My_Resource_Path", Assembly.GetExecutingAssembly());
string value = resourceManager.GetString("key");


string value = GetGlobalResourceObject("resource_name", "key").ToString();

I have a resx file. and the property "Build Action" set to Embedded Resource.

My problem is that when I publish my project it doesn't work. (because GetGlobalResourceObject retrieves resources from a global .resx file which is not generated, because my build action property set to embedded resource and not to content.

An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
8,981 questions
{count} votes

Accepted answer
  1. Jack J Jun 23,946 Reputation points Microsoft Vendor

    @Maor kam , I recommend that you used System.Resources.ResourceReader to read the resource file after publishing.

    You can refer to the following steps to do it.

    First, Please create a folder and add the resource file to the folder in your project.


    Second, Please change Build Action to Content.


    Third, we could use the following code to access the resource file after publishing.

      private void button1_Click(object sender, EventArgs e)  
                string paath = AppDomain.CurrentDomain.BaseDirectory + @"Data\ExampleResources.resources";  
                var rr1 = new System.Resources.ResourceReader(paath);  
                foreach (DictionaryEntry entry in rr1)  
                    if (entry.Key.ToString()=="Greeting")  
                        textBox1.Text = entry.Value.ToString();   

    Finally, we can see the following result:


    If the response is helpful, please click "Accept Answer" and upvote it.

    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

0 additional answers

Sort by: Most helpful