views:

2385

answers:

4

The situation:

  • I have a class library, called RT.Servers, containing a few resources (of type byte[], but I don't think that's important)
  • The same class library contains a method which returns one of those resources
  • I have a simple program (with a reference to that library) that only calls that single method

I get a MissingManifestResourceException with the following message:

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

I have never played around with cultures, or with assembly signing, so I don't know what's going on here. Also, this works in another project which uses the same library. Any ideas?

A: 

from Microsoft support page:

This problem occurs if you use a localized resource that exists in a satellite assembly that you created by using a .resources file that has an inappropriate file name. This problem typically occurs if you manually create a satellite assembly.

To work around this problem, specify the file name of the .resources file when you run Resgen.exe. While you specify the file name of the .resources file, make sure that the file name starts with the namespace name of your application. For example, run the following command at the Microsoft Visual Studio .NET command prompt to create a .resources file that has the namespace name of your application at the beginning of the file name:

Resgen strings.CultureIdentifier.resx 
MyApp.strings.CultureIdentifier.resources
TheVillageIdiot
Thanks for your response, but I don't know what ResGen.exe is, I've never used it, and frankly I don't want to use it because I'm not trying to use anything fancy. Surely there must be a way to fix this from Visual Studio? For example, since you say the resource is "localized", how do I declare a resource as non-localized? Thanks again.
Timwi
Oh the downvoter! please be nice to leave comment so that other can know what is wrong with this question or answer
TheVillageIdiot
I did. --------
Timwi
+8  A: 

All I needed to do to fix this problem was to right-click the Resources.resx file in the Solution Explorer and click Run Custom Tool. This re-generates the auto-generated Resources.Designer.cs file.

The problem is due to a mismatch of namespaces, which occurs if you change the "default namespace" of the assembly in the project settings. (I changed it from (previously) "Servers" to (now) "RT.Servers".)

In the auto-generated code in Resources.Designer.cs, there is the following code:

internal static global::System.Resources.ResourceManager ResourceManager {
    get {
        if (object.ReferenceEquals(resourceMan, null)) {
            global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Servers.Resources", typeof(Resources).Assembly);
            resourceMan = temp;
        }
        return resourceMan;
    }
}

The literal string "Servers.Resources" had to be changed to "RT.Servers.Resources". I did this manually, but running the custom tool would have equally well done it.

Timwi
This saved me a lot of time!
Eric
I love you. :-)
Stimul8d
+1! In VS 2010 the ResourceManager literal string shown above is automatically updated to the value of the Default Namespace in the project properties (Application tab), at least for WinForms.
TrueWill
+1  A: 

I just came across this problem today, and I found this Microsoft Help and Support page that actually did work around the problem.

I had a couple delegates at the top of my file, in the global namespace, and all of a sudden I was getting a MissingManifestResourceException when running the program, on this line:

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

Then I moved the delegates into the namespace, got the same error. Finally I put the delegates in the only class in that file, and the error went away, but I didn't want the delegates in that class or namespace.

Then I came across that link above, which said

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

I put the delegates (which I would not consider "class definitions") at the bottom of that file, outside of the local namespace, and the program didn't get the MissingManifestResourceException anymore. What an irritating error. But, that seems like a more robust solution than modifying the auto-generated code :)

Mark Rushakoff
Thanks for your answer. This sounds like you had a different problem which caused the same symptom. I didn't have any extra classes in my code, indeed I didn't even have any forms at all.I should edit my previous answer because I discovered I didn't actually need to modify the auto-generated code. I could have just re-run the code generator, and it would have fixed itself. No idea why the build process didn't do it automatically.
Timwi
+1  A: 

I had the same problem, but using the Run Custom Tool command as suggested by Timwi did not help in my case.

However it lead me into the right direction, because I ended up in the Properties of the .resx file. Here I noticed a difference to another .resx file that caused no problems.

In my case I had to change the property "Build Action" from "Resource" to "Embedded Resource".

My best guess for the reason is, that I had the .resx in a library that was used from another application. My application did not have its own .resx file, so it had to use the one from the library - which is only available when it's embedded in the library and not "stand alone".

BlaM