0
votes

I have some html code that I want to replace with text from resources.

My class looks like:

 public static class ResourceParser
    {
        public static string GetTextFromResource(string keyValue)
        {
            ResourceManager rm = new ResourceManager("pl", Assembly.GetExecutingAssembly());

            return rm.GetString(keyValue);
        }
    }

When I access resources from my view this way:

@Resources.pl.accept;

it works and displays the value I want.

When I do it like this:

@ResourceParser.GetTextFromResource("accept");

there is an exception

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

1
What is the name of the resource file and what is the file path?haldo
See if this link helps. Cannot post as answer yet as that would be just guessingAndrei
@Andrei I've changed to embedded resources and still the same problem occurs. Now The part that was working before is not working :PAlice
@Haldo the resource file name is pl.resx. The resource file is in different project actuallyAlice
What is the namespace of the project? I think it should be loaded using full namespace: new ResourceManager('Full.Namespace.WithoutExtension').haldo

1 Answers

0
votes

It started working somehow.

In the meantime I've added this method:

 protected void Application_AcquireRequestState(object sender, EventArgs e)
        {
            if (Request.UserLanguages != null)
            {
                string culture = Request.UserLanguages[0];

                Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo(culture);
                Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo(culture);
            }
        }

to my Global.asax.cs file

and I've change the code a bit:

public static string GetTextFromResource(string keyValue)
        {
            var path = "ProjectName.Folder.pl";

            var res_manager = new ResourceManager(path, typeof(pl).Assembly);

            return res_manager.GetString(keyValue);
        }