Could not find any resources appropriate for the specified culture or the neutral culture

后端 未结 30 1228
旧巷少年郎
旧巷少年郎 2020-11-28 20:15

I have two ASP.NET Web projects (ProjectA and ProjectB). When class in ProjectA is instantiating a class of ProjectB which uses a resource file Blah.resx, I get this error:

相关标签:
30条回答
  • 2020-11-28 20:59

    I just hit this same exception in a WPF project. The issue occurred within an assembly that we recently moved to another namespace (ProblemAssembly.Support to ProblemAssembly.Controls). The exception was happening when trying to access resources from a second resource file that exists in the assembly.

    Turns out the additional resource file did not properly move references from the old namespace name to the new namespace name.

    In the designer.cs for the resource file, there is a static property to get the ResourceManager. Within that getter, the string was still referring the old namespace. Once correcting it to the new namespace, the problem was resolved:

    global::System.Resources.ResourceManager temp = 
         new global::System.Resources.ResourceManager(
              "ProblemAssembly.Support.Properties.Stuff", typeof(Stuff).Assembly);
    

    should have been:

    global::System.Resources.ResourceManager temp = 
         new global::System.Resources.ResourceManager(
              "ProblemAssembly.Controls.Properties.Stuff", typeof(Stuff).Assembly);
    

    Hope this helps the next person.

    0 讨论(0)
  • 2020-11-28 20:59

    I solved the problem like this:

    1. Right click on your ResourceFile
    2. Change the "Build Action" property Compile to "Embedded Resource"
    3. Then build and run

    It works perfectly.

    0 讨论(0)
  • 2020-11-28 21:01

    This can be caused by mismatched namespaces. The second from top answer (Sibi Elango's) says to right-click the resx file, and change Build option to EmbeddedResource, but I had already done that and still had the error. The top answer (CFinck's) notes a way of fixing this via manually editing files, however, I had this problem in MonoDevelop, and had to set the default namespace to the same as the cs file which was calling for the resource (the file which contained code such as the code below)...

    this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
    

    After setting the default namespace via the GUI, the line above no longer caused an exception.

    0 讨论(0)
  • 2020-11-28 21:05

    When we were using

    HttpContext.GetGlobalResourceObject()
    

    It would generate that error unless we wrapped that call inside a try/catch statement.

    0 讨论(0)
  • 2020-11-28 21:06

    In my case these lines of code added to Web.config helped a lot:

    <system.web>
         ...
        <globalization uiCulture="cs" culture="cs-CZ" />
         ...
    <system.web>
    

    Together with Build action: Embedded Resource and Custom Tool: PublicResXFileCodeGenerator.

    0 讨论(0)
  • 2020-11-28 21:07

    This error is also raised by Dotfuscation, since a resx designer file relies on reflection. If you are using Dotfuscator it will break your resx files. You must always add them as an exclusion from the obfuscation process.

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