What's wrong with these 3 lines of code? (C#, .NET)
Posted on 2005-04-18
I am learning how to create a resource file and retrieve info from it. This is what I've done so far:
1. Create a text file ProductNames.txt and use resgen.exe to generate ProductNames.resources. This text file has only two lines:
Shirt = chemise
Hat = chapeau
2. I added ProductNames.resources to WindowsApplication1 project using Add Existing Item
3. Wrote code to display the resource string associated with "Shirt" on a button.
Here's the code:
private void btnLoad_Click(object sender, System.EventArgs e)
ResourceManager rm = new ResourceManager( "ProductNames", Assembly.GetExecutingAssembly() );
myString = rm.GetString("Shirt");
btnTestResource.Text = myString;
The following code compiled OK but when I run the program, I got the following error:
"An unhandled exception of type 'System.Resources.MissingManifestResourceException' occurred in mscorlib.dll
Additional information: Could not find any resources appropriate for the specified culture (or the neutral culture) in the given assembly. Make sure "ProductNames.resources" was correctly embedded or linked into assembly "WindowsApplication1"."
How else do I correctly embed the ProductNames.resources to the WindowsApplication1 assembly???? I thought what I did was correct.