ResourceManager trying to load .resources not .resx file
Asked Answered
M

5

13

I am trying to load a resx file in my .net website using:

ResourceManager rm = new ResourceManager( "Project.Resource", Assembly.GetExecutingAssembly() );

The Resource.resx file is in the folder App_LocalResources and is set to be embedded in assembly on build.

When I try to access the resx file using:

rm.GetString( "key" ); or rm.GetString( "key", culture );

I get an error message:

Could not find any resources appropriate for the specified culture or the neutral culture. Make sure "Project.Resource.resources" was correctly embedded or linked into assembly "Project" at compile time, or that all the satellite assemblies required are loadable and fully signed.

Notice the .resources ... any ideas on what is going on here?

Manning answered 22/9, 2009 at 15:59 Comment(1)
Isn't a designer file also created?Maneater
M
3

I think the way you are using ResourceManager is wrong. See this post.

Also note, when you open Visual Studio command prompt, & run resgen.exe, it says its used to convert resource files from one format to another (i.e. resx to resources). I think, you will need to convert your file to resources from resx & then load it using resourceManager.

Maneater answered 22/9, 2009 at 16:34 Comment(1)
Thanks for putting me on the right track ... I should not be using ResourceManager I ended up using the <%$Resources: filename, key %> syntax in my page insteadManning
T
21

To load .resx into ResourceManager you need specify namespace

var rm = new ResourceManager("Namespace.ResxName", Assembly.GetAssembly());

or you can get ResourceManager for free if set Access Modifier inside Managed Resource Editor to Internal or Public, after that VS will generate ResxName.Designer.cs

var rm = ResxName.ResourceManager;
Toehold answered 23/10, 2012 at 13:2 Comment(1)
+1 for the method of accessing resources through the Designer codeRuthenious
A
5

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).

Adrian answered 22/4, 2015 at 8:43 Comment(0)
M
3

I think the way you are using ResourceManager is wrong. See this post.

Also note, when you open Visual Studio command prompt, & run resgen.exe, it says its used to convert resource files from one format to another (i.e. resx to resources). I think, you will need to convert your file to resources from resx & then load it using resourceManager.

Maneater answered 22/9, 2009 at 16:34 Comment(1)
Thanks for putting me on the right track ... I should not be using ResourceManager I ended up using the <%$Resources: filename, key %> syntax in my page insteadManning
W
3

I'm not sure which version of .NET Framework are you using.

Try channging the way how you bring the ResourceManager to life.

ResourceManager rm = 
     new ResourceManager("Project.Resource", 
                         System.Reflection.Assembly.Load("App_LocalResources"));

It should work.

This is also exposed as a static property of the automatically generated .designer.cs class of the concrete resorce manager.

Woolfell answered 12/10, 2009 at 13:42 Comment(0)
A
-1

Add the .resx extension explicitly.

You can also use the auto-generated class and use its properties if that is suitable for your project.

Antipodes answered 22/9, 2009 at 16:2 Comment(2)
If I add the .resx to the "Project.Resource" I get the same error but for the file Project.Resource.resx.resourcesManning
Sorry, I missed that your .resx is in App_LocalResources. None of my post applies...Antipodes

© 2022 - 2024 — McMap. All rights reserved.