17

I have created an assembly and later renamed it.

Then I started getting runtime errors when calling:

toolsMenuName = resourceManager.GetString(resourceName);

The resourceName variable is "enTools" at runtime.

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

The code:

string resourceName;
ResourceManager resourceManager = new ResourceManager("Jfc.TFSAddIn.CommandBar", Assembly.GetExecutingAssembly());

CultureInfo cultureInfo = new CultureInfo(_applicationObject.LocaleID);

if(cultureInfo.TwoLetterISOLanguageName == "zh")
{
     CultureInfo parentCultureInfo = cultureInfo.Parent;
     resourceName = String.Concat(parentCultureInfo.Name, "Tools");
}
else
{
     resourceName = String.Concat(cultureInfo.TwoLetterISOLanguageName, "Tools");
}

toolsMenuName = resourceManager.GetString(resourceName); // EXCEPTION IS HERE

I can see the file CommandBar.resx included in the project, I can open it and can see the "enTools" string there. It seems that either resources are not included into assembly or resource are included but .NET cannot resolve the name.

krlzlx
  • 5,752
  • 14
  • 47
  • 55
Captain Comic
  • 15,744
  • 43
  • 110
  • 148

10 Answers10

31

I think simpler solution would be to create separate resources file for each language.

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"

dzendras
  • 4,721
  • 1
  • 25
  • 20
  • 7
    "check if the assembly containing resources has the default namespace set to the same text (Project->Properties->Default namespace; in VS)" - the same text of what? – Captain Comic Jan 14 '11 at 12:05
  • 6
    +1 for 'Check as well if the resx file has a property BuildAction set to "Embedded resource"' = Facepalm – Andiih Nov 17 '11 at 17:33
15

I'm sure you've already got the answer, but just in case:

  1. You can view your ManifestResourceName by calling

    System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceNames() 
    

    Check that Manifest name and your name in GetString() calling are identical.

  2. Also, be sure you have correct namespace in designer.resx file:

    namespace Jfc.TFSAddIn {
    ...
    global::System.Resources.ResourceManager temp = 
                 new global::System.Resources.ResourceManager(
                 "Jfc.TFSAddIn.CommandBar", typeof(CommandBar).Assembly);
    ... 
    }
    
  3. Open resx file properties: "Build Action" should be "Embedded Resource"

Olga Golubeva
  • 307
  • 2
  • 8
  • 1
    GetManifestResourceNames() is very helpful! Thank you a lot. – Mystic Lin Mar 17 '16 at 09:59
  • Wow!!! I scratching my hair why it doesn't work and I found that my namespace is wrong using `System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceNames()`. Thank you so much! – Sam May 12 '21 at 10:26
14

Sounds similar to an issue we had. The namespace was incorrect in the resource file's designer. I fixed it by manually re-running the custom-tool on the resx file.

Right click your.resx, and click Run Custom Tool.

firefox1986
  • 1,602
  • 11
  • 9
  • This was my issue. Looks like ReSharper had renamed the namespace during a refactor... – Ian Newson Apr 22 '15 at 13:05
  • Same issue here. The compiled Designer.cs still had the old namespace after moving the resource to a different project. Running the custom tool fixed it. THANKS! – Daniel Hillebrand Sep 19 '18 at 12:51
1

For me, the source of the problem was naming the rex files starting with a number:

20160216_tranlation.resx

I had to add an underscore _ before the resx file name when calling GetGlobalResourceObject:

public static string getResource(string key)
{
    return HttpContext.GetGlobalResourceObject("_20160216_tranlation", key).ToString();
}
krlzlx
  • 5,752
  • 14
  • 47
  • 55
0

I corrected the namespace in designer file (Resources.Designer.cs) in ResourceManager static property & it worked for me.

See the code below:

[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
    internal static global::System.Resources.ResourceManager ResourceManager {
        get {
            if (object.ReferenceEquals(resourceMan, null)) {
                global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("XYZAssembly.Properties.Resources", typeof(Resources).Assembly);
                resourceMan = temp;
            }
            return resourceMan;
        }
    }
  • I was able to solve this problem by just adding an additional entry into the resources. That forced the designer code to rebuild itself and correct the namespace issue. – Phillip Davis Mar 18 '16 at 12:21
0

I added a temporary class within my Form.cs while (testing || debugging) that caused this exception to be thrown. The Form.resx file (Name || Resource ID) was modified to the temporary class name instead of the Form class name. This caused the issue for me. I (corrected || alleviated) this by creating a separate file for my temporary class in the project.

user984899
  • 31
  • 3
0

One Solution is to change the property of resx file from content to Embedded Resource and Build it.Sure this time u vil get

Sai Saran
  • 92
  • 4
0

I have encountered this issue in Xamarin.Forms, when I tried to the rename the project, the resources could not be loaded anymore with the same stated error text.

To fix the problem I had to modify the .csproj by a text editor, and change the logical name of the embedded resource.

<EmbeddedResource Include="Localization\TextResources.resx">
      <Generator>ResXFileCodeGenerator</Generator>
      <LastGenOutput>TextResources.Designer.cs</LastGenOutput>
      <LogicalName>YourNewNamespaceName.TextResources.resources</LogicalName>
      <SubType>Designer</SubType>
</EmbeddedResource>

Also watch out for the autogenerated class when you rebuild it, the namespace stated in there might change.

Hope it helps someone that went into the same situation.

Wail
  • 137
  • 8
0

Got this error when I added a class ABOVE the partial form class in my Windows forms app.

It went away when I moved the class BELOW the partial form class.

-1

This answer solved the problem for me! GetGlobalResourceObject

Community
  • 1
  • 1
DanielV
  • 2,076
  • 2
  • 40
  • 61