Skip to content

ResourceManager has incorrect BaseName when constructed with a Type #74918

@madelson

Description

@madelson

Description

According to the docs:

the BaseName property reflects the fully qualified namespace name and the root resource name of a resource file, without its culture or file name extension. For example, if an app's default resource file is named SampleApps.StringResources.resources, the value of the BaseName property is "SampleApps.StringResources".

This is true when you access the generated MyResource.ResourceManager.BaseName property, which uses the ResourceManager(baseName, assembly) constructor.

However, if you construct a ResourceManager with just a Type, it sets BaseName to Type.Name which is different. The resource lookup still works because it uses the type's full name internally.

Reproduction Steps

Console.WriteLine(MyResourceType.ResourceManager.BaseName); // e.g. "MyNamespace.MyResourceType"
Console.WriteLine(new ResourceManager(typeof(MyResourceType)).BaseName); // e.g. "MyResourceType"

Expected behavior

The BaseName property should be initialized from the type's full name.

Actual behavior

The BaseName property is initialized from the type's name.

Regression?

No.

Known Workarounds

Don't use the ResourceManager(Type) constructor if you will be accessing the BaseName property. This is unfortunate because that is the easiest constructor to use.

Configuration

.NET 6 Windows 10 x64.

Other information

Possibly this is "by design" and the docs just need to be updated? Not sure why that would be the case, though.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-System.Resourcesbuggood first issueIssue should be easy to implement, good for first-time contributorshelp wanted[up-for-grabs] Good issue for external contributors

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions