ResourceManager trying to load .resources not .resx file

前端 未结 5 1639
陌清茗
陌清茗 2021-01-11 12:21

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

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


        
相关标签:
5条回答
  • 2021-01-11 13:00

    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.

    0 讨论(0)
  • 2021-01-11 13:04

    Add the .resx extension explicitly.

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

    0 讨论(0)
  • 2021-01-11 13:06

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

    0 讨论(0)
  • 2021-01-11 13:08

    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;
    
    0 讨论(0)
  • 2021-01-11 13:11

    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.

    0 讨论(0)
提交回复
热议问题