Click here to Skip to main content
15,888,521 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I need to be able to load resources at runtime and have used the following code in a simple C# test app :-

ResourceManager rm = new ResourceManager("ResourceTest.Resources", this.GetType().Assembly);

string someString = rm.GetString("MyString");
label1.Text = someString;

When I try to run the app, the call to GetString() on the second line of code throws a MissingManifestResourceException.

However, if I add a new Resource file to the project by right clicking the project node in the Solution Explorer and select Add | New Item | Resource File I get a new res file called, by default, Resource1.resx. I can then reference this file in the above code (changing the first param in the ResourceManager contructor to "ResourceTest.Resource1") and all works fine.

How come the default Resource file in the project won't work but any resource file I add will ?

BTW, I am using Visual Studio 2005 if it makes any difference ??

Thanks

Alan
Posted
Comments
Sergey Alexandrovich Kryukov 20-Jan-11 12:11pm    
You can do it, but I would like to see why? Adding resources in VS auto-generate static class which is very convenient, see Ron's sample.

1 solution

Why don't you just use label1.Text = Resources.MyString;?
 
Share this answer
 
Comments
fjdiewornncalwe 20-Jan-11 14:40pm    
OP Message moved from answer:
Rob

Thanks for that. I couldn't get it to work that way to start with. Then I realised the Resources sit inside the 'ResourceTest.Properties' namespace. Adding this to the using clauses allowed me to use the code you suggested.

Coming from a C++ background I find C# both interesting and frustrating in equal doses !

Thanks again

Alan

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900