When nesting a .resx file under a .cs file using the DependentUpon element in the .csproj file and then accessing a resource using the wrapper a MissingManifestResourceException is thrown.
The message reads:
Could not find any resources appropriate for the specified culture or the neutral culture. Make sure "Namespace.Resource.resources" was correctly embedded or linked into assembly "Assembly" at compile time, or that all the satellite assemblies required are loadable and fully signed.
Example code:
MessageBox.Show(Resource.Key);
Why does this error occur?
The MSBuild target
PrepareResourceNames(on whichPrepareResources, which also callsResGen, depends on) calls a task calledCreateManifestResourceName.[see
Microsoft.Common.targets]This task creates the name of the
.resourcesfile. For C# the actual method that creates the name isCreateManifestNameImplinMicrosoft.Build.Tasks.CreateCSharpManifestResourceName. This method checks whether the.resxfile has a.csfile as parent. In that case it searches the.csfile for the first fully qualified class name it can find and takes it as the.resourcesfile name.[see
Microsoft.Build.Tasks.v4.0.dll]The
.resxwrapper does not expect this file name change and thus an exception is thrown.I guess this behavior was implemented for WinForms localization which nests its resources under the corresponding form or control.
I decided not to nest the
.resxfiles. A possible solution could be to implement aCreateCustomManifestResourceNametask for which MSBuild provides a hook.