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

后端 未结 30 1226
旧巷少年郎
旧巷少年郎 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:56

    I resolved this by going to the project where my resources file was saved, scrolling down to its ItemGroup and adding a logical name that corresponded to the path the compiler expected.

    My EmbeddedResource looked like this:

       <ItemGroup>
        <EmbeddedResource Update="Properties\TextResources.resx">
          <Generator>PublicResXFileCodeGenerator</Generator>
          <LastGenOutput>TextResources.Designer.cs</LastGenOutput>
        </EmbeddedResource>
      </ItemGroup>
    

    Now it looks like this

      <ItemGroup>
        <EmbeddedResource Update="Properties\TextResources.resx">
          <Generator>PublicResXFileCodeGenerator</Generator>
          <LastGenOutput>TextResources.Designer.cs</LastGenOutput>
          <LogicalName>MyProject.Properties.Resources.resources</LogicalName>
        </EmbeddedResource>
      </ItemGroup>
    
    0 讨论(0)
  • 2020-11-28 20:56

    Thanks @CFinck ! Just to add a tip to others : I changed the ResourceManager line with this :

    New Global.System.Resources.ResourceManager(Reflection.Assembly.GetCallingAssembly.GetName.Name & ".CommonNameOf.Resources", Reflection.Assembly.GetCallingAssembly())
    

    I'm in vb.net but I think in C# the only difference would be + instead of & to concatenate strings.

    This way I can use the same linked assembly files in two similar projects that share the resources.

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

    I was also facing the same issue, tried all the solutions mentioned in the answer but none seemed to work. Turned out that during the checkin of code to TFS. TFS did not checkin the Resx file it only checked in the designer file. So all other developers were facing this issue while running on their machines. Checking in the resx file manually did the trick

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

    Just because you are referencing Project B's DLL doesn't mean that the Resource Manager of Project A is aware of Project B's App_GlobalResources directory.

    Are you using web site projects or web application projects? In the latter, Visual Studio should allow you to link source code files (not sure about the former, I've never used them). This is a little-know but useful feature, which is described here. That way, you can link the Project B resource files into Project A.

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

    For me the problem was copying .resx files and associated .cs files from one project to another. Both projects had the same namespace so that wasn't the problem.

    Finally solved it when I noticed in Solution Explorer that in the original project the .resx files were dependent on the .cs files:

    MyResource.cs
    |_ MyResource.resx
    

    While in the copied project the .cs files was dependent on the .resx files:

    MyResource.resx
    |_ MyResource.cs
    

    It turned out that in the second project somehow the .resx files had been set to auto-generate the .cs files. The auto-generated .cs files were overwriting the .cs files copied from the original project.

    To fix the problem edit the properties of each .resx file in the copied project. The Custom Tool property will be set to something like ResXFileCodeGenerator. Clear the Custom Tool property of the .resx file. You will need to re-copy the .cs file from the original project as it will have been overwritten by the auto-generated file.

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

    Yet another cause: if your namespace has a hyphen ("-"), then it will build and run correctly, but the resource won't be accessible. Namespaces (identifiers) aren't supposed to have hyphens, but this doesn't appear to be enforced anywhere except in loading resources. This has burned me twice over the decade.

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