Could not find the resource

Sergio23 271 Reputation points
2021-09-09T05:46:05.883+00:00

Hello to all
I have a problem with a sample C # resource program.

Program link: https://learn.microsoft.com/it-it/dotnet/api/system.resources.neutralresourceslanguageattribute?view=net-5.0

I follow all the instructions, I do all the builds, but when I run the program, it crashes with the following error:
System.Resources.MissingManifestResourceException: 'Could not find the resource "ExampleResources.resources" among the resources "" embedded in the assembly "Example", nor among the resources in any satellite assemblies for the specified culture. Perhaps the resources

Where is the problem?
Thanks

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,461 questions
0 comments No comments
{count} votes

1 additional answer

Sort by: Most helpful
  1. Timon Yang-MSFT 9,576 Reputation points
    2021-09-09T09:33:45.47+00:00

    I reproduced your problem but haven't found a solution yet.

    But there is another way to add resources, right click on the project=> Add=> New Item=>Resources File.

    130695-capture.png

    Then slightly modify the code in the document:

                string[] cultures = {  "en-us", "fr-FR" };  
                Random rnd = new Random();  
                int index = rnd.Next(0, cultures.Length);  
                Thread.CurrentThread.CurrentUICulture = CultureInfo.CreateSpecificCulture(cultures[index]);  
                Console.WriteLine("The current culture is {0}",  
                                  CultureInfo.CurrentUICulture.Name);  
      
                string grtting = ExampleResources.Greeting;  
      
                Console.Write("Enter your name: ");  
                string name = Console.ReadLine();  
                Console.WriteLine("{0} {1}!", grtting, name);  
                Console.ReadKey();  
    

    If the response is helpful, please click "Accept Answer" and upvote it.
    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.