0
votes

I used following article for using custom resources from database.

http://afana.me/post/aspnet-mvc-internationalization-store-strings-in-database-or-xml.aspx I am trying to get a string resource using this code:

string key = "Partner_Key";
        string title = new System.Resources.ResourceManager(typeof(MyDBResources)).GetString(key);

But I get error as :

An exception of type 'System.Resources.MissingManifestResourceException' occurred in mscorlib.dll but was not handled in user code

Additional information: Could not find any resources appropriate for the specified culture or the neutral culture. Make sure "MyResources.MyDBResources.resources" was correctly embedded or linked into assembly "[ProjectName]" at compile time, or that all the satellite assemblies required are loadable and fully signed.

The Resource provider code is like:

   namespace MyResources {
            public class MyDBResources {
                private static IResourceProvider resourceProvider = new DbResourceProvider();

    public static string Partner_Key {
                   get {
                       return (string) resourceProvider.GetResource("Partner_Key", CultureInfo.CurrentUICulture.Name);
                   }
                }
---
}

Other side, the Database resource table has values for all keys.

Any help?

1

1 Answers

0
votes

Since there is no direct method to get the string resource by key name, I just inherit the Resource class by new class "ResxExtended" and added a method:

public class ResxExtended : MyDBResources
    {
        private static IResourceProvider resourceProvider = new DbResourceProvider();

        public static string GetStringResx(string resourcekey)
        {

            return (string)resourceProvider.GetResource(resourcekey, CultureInfo.CurrentUICulture.Name);

        }

    }

Then simply from view we use:

  string title = [project].[namespace].ResxExtended.GetStringResx("PartnerKey");

It is working now.