Using ResourceManager
Using ResourceManager
I'm trying to use the ResourceManager in a C# class, but don't know what to substitute for the basename when creating a new instance of the ResourceManager class.
I have a separate project that contains the resource files which is referenced by my project above named as the following: ?Resources.resx ?Resources.es-ES.resx
If I have a code snippet as follows, what should I substitute for the basename when I want to use the English or Spanish version of the resources?
ResourceManager RM = new ResourceManager(basename,Assembly.GetExecutingAssembly());
I tried the approach suggested by Tom, but am getting the infamous error "Could not find any resources appropriate for the specified culture or the neutral culture".
I have 2 projects where project YeagerTech is a web application project and project YeagerTechResources is a project (in the same solution) that contains all the resources. Project YeagerTech has a reference in it to YeagerTechResources.
I have the following syntax when creating my Resource Manager:
ResourceManager RM = new ResourceManager("YeagerTechResources.Resources", Assembly.GetExecutingAssembly());
Obviously, it's incorrect.
The resource files in the YeagerTechResources project have their BuildAction set to Embedded Resource.
The name of my resource files are: Resources.resx and Resources.es-ES.resx.
If someone can simply tell me the exact syntax to use based on my project and resource file names when instantiating the resource manager, I would greatly appreciate it...
I've done everything I can think of to resolve this and can't....
This is my last attempt to resolve it here...
ResourceManager RM = new ResourceManager("YeagerTechResources.Resources", Assembly.GetExecutingAssembly());
I am getting the following error after executing the following code:
sb.Append(RM.GetString("RegisterThanks"));
Could not find any resources appropriate for the specified culture or the neutral culture. Make sure "YeagerTechResources.Resources.resources" was correctly embedded or linked into assembly "YeagerTech" at compile time, or that all the satellite assemblies required are loadable and fully signed.
I have one solution and two projects. One is the web project and the other is the resources project. The resources project is contained as a reference in the web project.
I am able to use the resources in the HTML markup with absolutely no issues, but when coming to the C# code in the Controller, I keep on getting the above error.
Any help for the exact syntax I need based on my projects would be greatly appreciated.
Answer by Tom Lint for Using ResourceManager
According to the MSDN documentation here, The basename argument specifies "The root name of the resource file without its extension but including any fully qualified namespace name. For example, the root name for the resource file named
The ResourceManager will automatically try to retrieve the values for the current UI culture. If you want to use a specific language, you'll need to set the current UI culture to the language you wish to use.
Answer by SinOB for Using ResourceManager
The quick and dirty way to check what string you need it to look at the generates .resources files.
Your .resources are generated in the resources projects obj/Debug directory. (if not right click on .resx file in solution exploere and hit 'Run Custom Tool' to generate the .resources files)
Navagitate into this directory and have a look at the filenames. You should see a file ending in XYZ.resources. Copy that filename and remove the trailing .resources and that is the file you should be loading.
For example in my obj/Bin directory I have the file:
MyLocalisation.Properties.Resources.resources
If the resource files are in the same Class library/Application I would use the following C#
ResourceManager RM = new ResourceManager("MyLocalisation.Properties.Resources", Assembly.GetExecutingAssembly());
However, as it sounds like you are using the resources file from a separate Class library/Application you probably want
Assembly localisationAssembly = Assembly.Load("MyLocalisation"); ResourceManager RM = new ResourceManager("MyLocalisation.Properties.Resources", localisationAssembly);
Answer by superjos for Using ResourceManager
This SO answer might help in this case.
If the main project already references the resource project, then you could just explicitly work with your generated-resource class in your code, and access its ResourceManager
from that. Hence, something along the lines of:
ResourceManager resMan = YeagerTechResources.Resources.ResourceManager; // then, you could go on working with that ResourceSet resourceSet = resMan.GetResourceSet(CultureInfo.CurrentUICulture, true, true); // ...
Answer by Landeeyo for Using ResourceManager
There's surprisingly simple way of reading resource by string:
ResourceNamespace.ResxFileName.ResourceManager.GetString("ResourceKey")
It's clean and elegant solution for reading resources by keys where "dot notation" cannot be used (for instance when resource key is persisted in the database).
Answer by leguminator for Using ResourceManager
I went through a similar issue. If you consider your "YeagerTechResources.Resources", it means that your Resources.resx is at the root folder of your project.
Be careful to include the full path eg : "project\subfolder(s)\file[.resx]" to the ResourceManager constructor.
Fatal error: Call to a member function getElementsByTagName() on a non-object in D:\XAMPP INSTALLASTION\xampp\htdocs\endunpratama9i\www-stackoverflow-info-proses.php on line 72
0 comments:
Post a Comment