I have problems with resource files .resources

Sergio23 271 Reputation points
2021-07-09T11:49:22.35+00:00

hello to everyone
Excuse me for my horrible English

Link: Create resource files for .NET apps | Microsoft Learn

C Sharp:
I have problems with resource files .resources
I followed the instructions with the example:
The following example uses a resource file in text format named GreetingResources.txt for a simple "Hello World" console application. The text file defines two strings, prompt and greeting, that prompt the user to enter their name and display a greeting.

GreetingResources.txt

A resource file in text format for a "Hello World" application.

Initial prompt to the user.

prompt=Enter your name:

Format string to display the result.

greeting=Hello, {0}!

The text file is converted to a .resources file by using the following command:

resgen GreetingResources.txt

output:
Reading in resources 2 from "GreetingResources.txt".
Writing to resource files in progress.... Completed..:

now the GreetingResources.resources file is in the project

The following example shows the source code for a console application that uses the .resources file to display messages to the user.

using System;
// using System.Reflection; is not used ???
using System.Resources;

public class Example
{
public static void Main()
{
ResourceManager rm = new ResourceManager("GreetingResources",
typeof(Example).Assembly);
Console.Write(rm.GetString("prompt")); // Error**
string name = Console.ReadLine();
Console.WriteLine(rm.GetString("greeting"), name);
}
}
// The example displays output like the following:
// Enter your name: Wilberforce
// Hello, Wilberforce!

Error**
Unhandled exception
'Could not find the resource "GreetingResources.resources" among the resources "" embedded in the assembly "Risorse_03_090721", nor among the resources in any satellite assemblies for the specified culture. Perhaps the resources were embedded with an incorrect name.'

Why doesn't it work?

C#
C#
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.
10,924 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Lex Li (Microsoft) 5,582 Reputation points Microsoft Employee
    2021-07-09T16:08:51.713+00:00

    "Why doesn't it work?" Because out of the five ways listed in that article, you chose the most difficult one which requires quite a few manual steps beyond what you did ("now the GreetingResources.resources file is in the project" is far from enough).

    Please check out the "Use Visual Studio to create a resource file ..." way instead, and that should save you a lot of time.

    0 comments No comments

  2. Sergio23 271 Reputation points
    2021-07-22T04:55:39.233+00:00

    the sample code works, I made an error with resource file Path

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.