Resource files not detected when using restext files

623 views Asked by At

I am working on the HealthVault SDK from Microsoft, I am trying to include a few translations for the text resources provided with SDK.

This is a piece of resource file used

resources.restext

# Used in many files
ListSeparator=, 
ListFormat=, {0}
GroupSeparator=;
GroupFormat=; {0} 
Range={0} - {1}
DateRange={0} to {1}

This is the code that initializes the Resource manager.

private static ResourceManager InitRMWithAssembly(
        string baseName,
        Assembly assemblyToUse,
        Type usingResourceSet)
    {
        ResourceManager rm = null;

        if (usingResourceSet != null &&
            baseName != null &&
            assemblyToUse != null)
        {
            rm =
                new ResourceManager(
                    baseName,
                    assemblyToUse,
                    usingResourceSet);
        }
        else if (usingResourceSet != null &&
                 baseName == null &&
                 assemblyToUse == null)
        {
            rm = new ResourceManager(usingResourceSet);
        }
        else if (usingResourceSet == null &&
                 baseName != null &&
                 assemblyToUse != null)
        {
            rm = new ResourceManager(baseName, assemblyToUse);
        }
        else
        {
            throw new ArgumentException("assemblyToUse cannot be null", "assemblyToUse");
        }

        return rm;
    }

where baseName is resources, assemblyToUse is Assembly.GetCallingAssembly().

The default strings are present in a text file named resources.restext. I wish to translate a few strings to Swedish and I added resources.sv-se.restext and made the translations. When I built the project, Satellite assembles were created in the bin folder inside a folder named sv-se. But the strings are still taken from the default resource file. I modified the default file and the changes are reflected immediately.

I tried loading the dll manually and the manifest names consisted of a name Microsoft.Health.ItemTypes.resources.sv-se.resources. I initialized the ResourceManager with that name and the same assembly.

var rm = new ResourceManager("Microsoft.Health.ItemTypes.resources.sv-se.resources", assembly);
rm.GetString("Key"); // Causes MissingManifestResourceException

However, I tried and was able to get the key by using the following

var rm = new ResourceManager("Microsoft.Health.ItemTypes.resources.sv-se", assembly); // manifest name - trailing resources
rm.GetString("Key"); // works!

My question is this:

What is the correct way to use ResourceManger? Should the satellite assembly be passed to the RM constructor? and how must be the resource files named, so that I do not have to edit the manifest name to create the resource manager instance?

1

There are 1 answers

0
rjv On

Solved.

In the .csproj for the project, the logical name of the resource was changed.

Changing the csproj to following solved my issues

<ItemGroup>
  <EmbeddedResource Include="resources.restext">
    <LogicalName>resources.resources</LogicalName>
  </EmbeddedResource>
  <EmbeddedResource Include="resources.sv-se.restext">
    <LogicalName>resources.sv-se.resources</LogicalName>
  </EmbeddedResource>
</ItemGroup>