MissingManifestResourceException when running tests after building with MSBuild (.mresource has path in manifest)

3

I am having a problem with embedded resources for a C# project on a build server using MSBuild on the command line. The project works just fine when building and running tests in Visual Studio, but when running MSBuild from the command line I get the following problems when running a test:


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

System.Resources.ManifestBasedResourceGroveler.HandleResourceStreamMissing(String fileName) at System.Resources.ManifestBasedResourceGroveler.GrovelForResourceSet(CultureInfo culture, Dictionary`2 localResourceSets, Boolean tryParents, Boolean createIfNotExists, StackCrawlMark& stackMark) at System.Resources.ResourceManager.InternalGetResourceSet(CultureInfo requestedCulture, Boolean createIfNotExists, Boolean tryParents, StackCrawlMark& stackMark) at System.Resources.ResourceManager.InternalGetResourceSet(CultureInfo culture, Boolean createIfNotExists, Boolean tryParents) at System.Resources.ResourceManager.GetString(String name, CultureInfo culture) at Properties.Resources.get_SomeResource() in \Properties\Resources.Designer.cs:line 87


I have tracked the problem down into the generated IL (I use ildasm). When bulding in Visual Studio, the following is set in the manifest of the assembly:

.mresource public <PROJECTNAME>.Properties.Resources.resources
{
  // Offset: 0x00000000 Length: 0x00000236
}

but when building using MSBuild the following output is generated:

.mresource public '../..//Build/<PROJECTNAME>_AnyCPU_Debug_Obj/<PROJECTNAME>.Properties.Resources.resources'
{
  // Offset: 0x00000000 Length: 0x00000236
}

as one can see the path to the resource is suddenly part of the resource name.

Does anyone have any ideas how to fix this?

c#
visual-studio-2010
msbuild
embedded-resource
il
asked on Stack Overflow Aug 16, 2011 by nietras

1 Answer

8

It appears adding LogicalName to the project file fixes it:

<LogicalName>$(RootNamespace).Properties.Resources.resources</LogicalName> 

i.e. so the embedded resource entry in the project file looks like this:

<ItemGroup>
  <EmbeddedResource Include="Properties\Resources.resx">
    <Generator>ResXFileCodeGenerator</Generator>
    <LastGenOutput>Resources.Designer.cs</LastGenOutput>
    <LogicalName>$(RootNamespace).Properties.Resources.resources</LogicalName> 
  </EmbeddedResource>
</ItemGroup>

This is detailed in: http://blogs.msdn.com/b/msbuild/archive/2007/10/19/manifest-resource-names-changed-for-resources-files.aspx

Note that we are using a .resx file, but the bug still appears to occur.

answered on Stack Overflow Aug 17, 2011 by nietras

User contributions licensed under CC BY-SA 3.0