Question

When you create a new C# Windows Forms Application in Visual Studio 2012, It has a Properties folder containing a Resources.resx file.

How do I access this file?

I have tried:

ResourceManager rm=new ResourceManager("Resources.resx",typeof(MyClass).Assembly);
string s=rm.GetString("MyString");

But I get System.Resources.MissingManifestResourceException because for some reason it appends .resources to the filename so it's looking for Resources.resx.resources. I then appended .resources to the filename to see if it might actually work. It didn't, same exception, why?

I also tried using the ResxResourceReader class but it looks for a resx file in a directory, and this specific resx file I'm trying to access is not stored in a directory, it's compiled in to my assemblies so that doesn't seem to be helping either.

I thought it'd be really simple, maybe it is and I'm just overlooking something?

If it's not simple, I might as well create a C# class and hard-code my strings (only type of resource I need right now).

And another question: If the resx file is compiled in to your exe, does that mean you can't change it's values during runtime?

Was it helpful?

Solution

It is plain simple (usually).

Use the Properties class!

Properties.Resources.MyString

The Properties folder you see in your Solution Explorer is not just a fancy folder ;p Visual Studio generates a class to access all your resources with ease.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top