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

33

231

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:

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

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

Whats causing this?

There is an article on Microsoft's site about this http://support.microsoft.com/kb/318603 which suggests:

To resolve this problem, move all of the other class definitions so that they appear after the form's class definition.

This is a solution for Windows Forms project, I'm not sure if that also applies to Web projects.

Rosanarosane answered 13/1, 2010 at 16:38 Comment(2)
What type of projects are these? 2 websites? 1 website, 1 class library?Crabtree
Two ASP.NET Website Projects.Rosanarosane
R
284

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

last line should have been:

global::System.Resources.ResourceManager temp = 
     new global::System.Resources.ResourceManager(
          "ProblemAssembly.Controls.Properties.Stuff", typeof(Stuff).Assembly);
Retrogradation answered 11/5, 2011 at 19:6 Comment(9)
link: MSDN documentation for the ResourceManager class.Depurate
Thanks it helped me solve this issue. One can also delete the designer file, then open then save the resx file to regenerate the designer file correctly.Hepza
I had the same issue and this was the answer I was looking for. Sadly it doesn't appear at compile time :-( ThanksIdolist
One more thing to note: this temp string does not get updated if you set a custom namespace to use under resource file properties (that's where you also choose a custom tool)Apace
One last thing to note: Resharper will not update this namespace reference when using it's 'Adjust Namespaces' command on a resx file (at least as of 8.2.1000)Spermatogonium
I have the same problem but cant fix it :( #29491366Bowen
thanks had this problem too but it was because I added a subfolder with the same name as the last part of the namespace of the project so it was looking for project.folder.folder.class instead of project.folder.class. I moved it to the root and now it lines up and works!Darkling
In my case it was an icon which wasn't handled correctly, but this answer gave me enough clues to know what to look for and find the issue. I just removed the icon and added it back. Not sure how to actually fix it.Ubald
Thanks @Depurate for the link to the docs... I clicked there, and it led me to a separate Remarks documentation learn.microsoft.com/en-us/dotnet/fundamentals/runtime-libraries/… , and particularly helpful for me was the fact that xcopy doesn't work if the *.resx files aren't included in the csproj. So I made sure to explicitly add those already existing files to the project, then I recompiled via msbuild (via Visual Studio) and it worked, no errors anymore.Impediment
E
127

I solved the problem like this:

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

It works perfectly.

Evelynneven answered 8/8, 2012 at 12:42 Comment(6)
@sibi Elango I right click on my ResourceFile but can't find the Build Action part.Circosta
@Circosta If you don't see this in the context menu (right click), look in the Properties panel (usually located below the solution explorer).Macrocosm
Its build action but still not working. Also I checked the directory and directory is the same under properties.Hawkweed
It would be great if the answer explains why this solution works.Phenoxide
For me I just did a rebuild and that fixed my issue. But I also r-clicked on my resource file --> Properties and verified "Build Action" to show "Embedded Resource". Worked fine.Airsick
For me, the issue was my ResourceFile wasn't being included in the project (imported form). This works because the second half of this error message says "Make sure "Form1.resources" was correctly embedded or linked into assembly "ProjectA" at compile time, or that all the satellite assemblies required are loadable and fully signed." and these resource files weren't being embedded because their build action didn't say to embed them (or in my case, to include them).Calyces
G
34

When I tried sharing a resource.resx file from one C# project with another C# project, I got this problem. The suggestion on moving the Form class to the beginning of its file wasn't appropriate. This is how I solved it. You essentially use a link from the second project to the first, then enable regeneration of the resource.designer.cs file.

  1. Delete the second project's Properties/Resources.resx file
  2. Add the first project's Properties/Resources.resx file as a LINK to the Properties folder in the second project. Don't add it to the root level of the project.
  3. Don't add the first project's Properties/Resources.designer.cs!
  4. On the properties of the second project's Resources.resx, add ResXFileCodeGenerator as the CustomTool
  5. Right click on the Resources.resx and select "Run Custom Tool". This will generate a new designer.cs file.

Note: I would avoid editing the resource.designer.cs file, as this is autogenerated.

Giacobo answered 12/7, 2013 at 20:11 Comment(1)
This only works if you do not have a Resources.resx file already in the target/second project that you want to keep.Clyster
T
19

For users who facing this isssue in .NET Core 3.0, this could be related to a breaking change that made in .NET Core 3.0, to resolve it just set EmbeddedResourceUseDependentUponConvention to false in your project csproj:

<PropertyGroup>
  <EmbeddedResourceUseDependentUponConvention>true</EmbeddedResourceUseDependentUponConvention>
</PropertyGroup>
Temporize answered 19/5, 2020 at 12:36 Comment(2)
This was the solution for me, except my problem was with a Winforms project that I'd ported to an SDK-style project. In this case, I had to set EmbeddedResourceUseDependentUponConvention to true rather than false.Morril
This solved the problem for me when referencing a private NuGet package containing a project in the SDK style. It seems that the resources are named according to the filename instead of the class name when it is an SDK-style project where as in the old format only the class name and namespace gets used.Seaden
S
18

In my case a series of badly thought global text replacements had inadvertently changed this line in the resource designer cs file.

enter image description here

Since the namespace in that argument did not match the namespace of the class anymore, the application got confused at run time.

Check that the namespace of the designer matches the string argument in that line.

Seclusion answered 7/4, 2016 at 18:20 Comment(2)
Same here: it happened after migrating from PCL to .NET Standard, when i created a temporary project and namespace, into which i copied all portable files, removed the portable project and reverted the namespace back to the original, this line still contained the temporary namespace from the migration process.Drida
my case: I create .resx file with Rider with '.' (dot) in name, generator autoreplace '.' to '_' in RecourceManager parameter. 'Could not find the resource' as a resultRattlebrained
C
15

It happens because the *.resх is excluded from migration.

  • Right click on your ResourceFile
  • Click on the menu item "Include in project"
Candidate answered 9/12, 2016 at 11:25 Comment(1)
This fixed it for me. Normally the resx file is added automatically. I did a merge where I had to change the project file and add the migrations manually, so maybe that had something to do with itBestial
J
11

I found that deleting the designer.cs file, excluding the resx file from the project and then re-including it often fixed this kind of issue, following a namespace refactoring (as per CFinck's answer)

Jean answered 30/9, 2013 at 22:45 Comment(0)
S
11

No-one seems to have mentioned this solution. Obvious really - but tripped me over for a moment...

The default access modifier for a new resources file is Internal (or Friend in VB.Net.) Make sure you change this to Public

(in the resx designer there is a dropdown at the top for the access modifier)

Shaquitashara answered 17/8, 2018 at 11:33 Comment(0)
D
7

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>
Demonstrative answered 28/4, 2018 at 17:53 Comment(0)
S
5

Sibi Elangos's answer alone was not sufficient for me, so I had to:

  • Right click on your ResourceFile
  • Change the "Build Action" property
  • Compile to "Embedded Resource"
  • Build and deploy

This will generate an App_GlobalResources in your /bin folder, now copy that folder also to the root of the web application

Sybaris answered 5/8, 2016 at 17:6 Comment(0)
H
5

In my case, the issue caused by the wrong order of class definitions. For example, I had added another class definition before my Form class:

namespace MyBuggyWorld
{
    public class BackendObject //This hack broke the VS 2017 winform designer and resources linker!
    {
        public TcpClient ActiveClient { get; set; }
        public BackgroundWorker ActiveWorker { get; set; }
    }

    public partial class FormMain : Form
    {
    }
}

After moving BackendObject to the end of the file (better yet would be to move it to a separate file), doing project clean + rebuild resolved the issue.

Haakon answered 8/2, 2018 at 3:36 Comment(1)
Wow, I was not aware that having the wrong class at the start of the file would break things so badly.Veronaveronese
V
4

As far as this case is concerned check if the assembly containing resources has the default namespace set to the same text (Project->Properties->Default namespace; in VS) Check as well if the resx file has a property BuildAction set to "Embedded resource" Enjoy... ;)

Virg answered 18/12, 2014 at 8:52 Comment(1)
Hi, do you mean that the default namespace (xxx) text should be the same as in the code: Assembly localisationAssembly = Assembly.Load("xxx"); ResourceManager resourceManager = new ResourceManager("xxx", localisationAssembly);Rudder
P
3

One approach would be to put the shared classes/resources in a separate class library project and refer them in both the web sites.

Peddada answered 8/2, 2010 at 11:34 Comment(1)
Surely this is the same problem then, isn't it?Bedder
B
3

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.

Boggs answered 11/11, 2011 at 19:23 Comment(0)
C
3

Just another case. I copied a solution with two projects and renamed them partially in the Windows explorer (folder names, .sln and .csproj file names) and partially with a massive Find & Replace action in Visual Studio (namespaces etc.). Nevertheless the exception stated by the OP still occurred. I found out that the Assembly and Namespace names were still old.

Although the project and everything else was already named OfficeStyle the Assembly name and Default namespace were still named Linckus.

Old situation

After this correction everything worked fine again, compile and run time :)

New situation

Correspondent answered 9/8, 2019 at 8:21 Comment(0)
F
2

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.

Fonzie answered 20/9, 2012 at 20:31 Comment(0)
D
2

When we were using

HttpContext.GetGlobalResourceObject()

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

Dickson answered 30/5, 2013 at 17:55 Comment(0)
U
2

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.

Undercroft answered 1/4, 2015 at 9:27 Comment(0)
A
2

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.

Aglitter answered 30/11, 2017 at 22:32 Comment(0)
B
2

You can also run into this exception when migrating a Windows Forms csproj to the new SDK-style project format. If you have any forms or user controls in subfolders, the *.resx files will generate using a namespace that includes the subfolder, which may not match the *.Designer.cs namespace. The solution is to add the following to the csproj:

<EmbeddedResourceUseDependentUponConvention>true</EmbeddedResourceUseDependentUponConvention>

https://learn.microsoft.com/en-us/dotnet/core/project-sdk/msbuild-props#embeddedresourceusedependentuponconvention

Blueweed answered 15/9, 2021 at 1:58 Comment(0)
E
1

I have a WinForms application with a single project in the solution. Targeting .NET Framework 4.0

Using SharpDevelop 4.3 as my IDE

Sounds silly, but I happened to have the Logical Name property set to "Resources" on my "Resources.resx" file. Once I cleared that property, all works hunky-dory.

Normally, when you add random files as EmbeddedResource, you generally want to set the Logical Name to something reasonable, for some reason, I did the same on the Resources.resx file and that screwed it all up...

Epaminondas answered 10/6, 2014 at 20:49 Comment(0)
F
1

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.

Fluoride answered 15/9, 2014 at 19:20 Comment(0)
H
1

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.

Heavyladen answered 9/2, 2019 at 19:25 Comment(1)
It would appear that '_' also causes the problemBerube
P
1

I faced this issue for running Migration command.Update-Database in Package Manager console.

Accepted answer didn't solve my problem.

I had to change Build Action from Compile to Embedded Resource and It worked for me.

You can do the same using below steps:

  1. Right click on migration.
  2. Change the "Build Action" property "Compile" to "Embedded Resource"
  3. Run Update-Database command.
Paleolithic answered 3/1, 2020 at 14:49 Comment(0)
B
1

In my case I was trying to migrate a Form from one project to another. It turns out I only forget to add Form.resx to the new project. In the form I was using some icons so it was dependent to resources.

Balsamic answered 9/8, 2021 at 9:10 Comment(0)
O
1

For me it was the following. In the MyStrings.Designer.cs file:

global::System.Resources.ResourceManager temp = 
    new global::System.Resources.ResourceManager(
      "MyApplication.MyProject", typeof(MyStrings).Assembly);

I had assumed that MyApplication.MyProject referred to the Namespace of the class rather than the directory of the file. I had placed the files in a subdirectory called Resources but the namespace didn't reflect that.

I changed it to

global::System.Resources.ResourceManager temp = 
    new global::System.Resources.ResourceManager(
      "MyApplication.MyProject.Resources", typeof(MyStrings).Assembly);

And it worked! (I didn't even have to update the namespace!)

Ossuary answered 5/5, 2022 at 15:7 Comment(0)
U
0

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

Undertrick answered 28/2, 2018 at 12:56 Comment(0)
C
0

Another thing to check is if you have LogicalName or ManifestResourceName defined on the EmbeddedResource. Make sure those are defined appropriately if your project file is using them as they can cause the resources to live under a name you are not expecting.

Cholinesterase answered 24/5, 2019 at 19:53 Comment(0)
P
0

I had the same issue when trying to run an update-database command on EF. Turns out the migration that was throwing the exception had the .resx file excluded from the project. I just right-clicked the .resx file and clicked "Include In Project". Problem solved.

Pocketknife answered 17/2, 2021 at 13:18 Comment(0)
A
0

In my case, Build Action of the resource file was already Embedded Resource but every time I ran update-database, I got the same error, so i did the fellow steps and it's worked:

  1. Change Build Action property to Compile
  2. Build (got so many errors)
  3. Change back Build Action property to Embedded Resource
  4. update-database

And for some reason it's worked.

Acosta answered 18/2, 2021 at 17:1 Comment(0)
E
0

Had a similar issue for a NetCore project and I noticed that after I added my migration (let's name it WhateverMigration), the .resx file reference as EmbeddedResource was not added to the .csproj even tho everything seemed fine. So I opened my .csproj file and I added:

<EmbeddedResource Update="Migrations\202107071914322_WhateverMigration.resx">
    <Generator></Generator>
    <DependentUpon>202107071914322_WhateverMigration.cs</DependentUpon>
</EmbeddedResource>
Ebb answered 7/7, 2021 at 19:30 Comment(0)
T
0

None of the other answers solved it for me. I had moved a number of forms and controls from one assembly to another, fixed all the namespaces and raN into this issue.

To keep the moved controls and forms separate from the rest I had put them in a subfolder. One resource reference was updated as suggested in one of the other answers. The IDE was warning me about the file path not matching the namespace with a blue squiggly but that is not an error so I initially ignored it.

When nothing appreared to fix it for me and I did not know anything better to try anymore I finally moved the controls and forms out of their subfolder (which was not expressed in the namespace) and the problem was gone.

Apperently there is still some hard dependency in WinForms on the folder structure.

Territorial answered 14/1, 2022 at 11:5 Comment(0)
D
-1

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.

Drugi answered 28/1, 2010 at 15:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.