MissingManifestResourceException while accessing a resource wrapper for a .resx file nested in a .cs file

When you attach a file .resx

to a file .cs

using an item DependentUpon

in a file .csproj

and then access the resource using a wrapper, it is created MissingManifestResourceException

.

The message says:

Could not find resources suitable for the specified culture or neutral culture. Make sure Namespace.Resource.resources has been properly embedded or connected to the Assembly at compile time, or that all required assemblies are loaded and fully signed.

Sample code:

MessageBox.Show(Resource.Key);

      

Why does this error occur?

+3


source to share


1 answer


The MSBuild target PrepareResourceNames

( PrepareResources

which also calls ResGen

depends on) invokes a task named CreateManifestResourceName

.
[cm. Microsoft.Common.targets

]

This task creates a filename .resources

. For C #, the actual method that creates the name is CreateManifestNameImpl

in Microsoft.Build.Tasks.CreateCSharpManifestResourceName

. This method checks if the file has a .resx

file .cs

as parent. In this case, it looks for the file .cs

for the first fully qualified class name it can find and takes that as the file name .resources

.
[cm. Microsoft.Build.Tasks.v4.0.dll

]

The shell .resx

does not expect this filename to change, and thus an exception will be thrown.



I assume this behavior was implemented for localization of WinForms, which nests in its resources in the appropriate form or control.

I decided not to insert files .resx

. A possible solution would be to implement the task CreateCustomManifestResourceName

for which MSBuild provides a hook.

+2


source







All Articles