-
Notifications
You must be signed in to change notification settings - Fork 4.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ResourceManager has incorrect BaseName when constructed with a Type #74918
Comments
Tagging subscribers to this area: @dotnet/area-system-resources Issue DetailsDescriptionAccording to the docs:
This is true when you access the generated However, if you construct a Reproduction StepsConsole.WriteLine(MyResourceType.ResourceManager.BaseName); // e.g. "MyNamespace.MyResourceType"
Console.WriteLine(new ResourceManager(typeof(MyResourceType)).BaseName); // e.g. "MyResourceType" Expected behaviorThe Actual behaviorThe Regression?No. Known WorkaroundsDon't use the Configuration.NET 6 Windows 10 x64. Other informationPossibly this is "by design" and the docs just need to be updated? Not sure why that would be the case, though.
|
Thanks for the report @madelson. Let us know if you are interested in throwing in a PR for this fix as well 👍 |
@joperezr sure I'll put together a quick fix for this! |
This property is documented to return the "qualified namespace name and the root resource name of a resource file". However, previously when constructing a ResourceManager with a Type the BaseName property would instead return the name of the type without its namespace. fix dotnet#74918
Have you checked the It might be explaining the behavior you are seeing.
I feel like it is by design, this constructor overload is used in so many places and the |
@buyaa-n thanks I hadn't seen that note. I don't think it covers exactly what I'm describing here (since it is talking about commandline vs. VS behavior whereas I'm talking about constructing a
So this "bug" doesn't impact loading resources because currently the Why I consider it a bug is that the current behavior makes the Currently, you can have 2 If there is a reason why this makes sense OR if it doesn't make sense but there is a desire to just leave things as is out of caution, that's fine and I'd just send a PR to update the docs to call out what the actual behavior is for the different constructors. |
Yes, it is not exactly explaining the behavior but at least mentions BaseName can omit the namespace Found better explanations from the constructor doc ResourceManager(Type):
From the
It seems the BaseName used for retrieving resource file name when changing locale(language), I would test that behavior before making this change. https://source.dot.net/#System.Private.CoreLib/src/libraries/System.Private.CoreLib/src/System/Resources/ResourceManager.cs,322 |
Hmm I'm not sure I see an explanation in the docs you referenced. This is just saying that you can use
Yes, Just to back out a bit, the essence of the issue here is that today The benefit of changing it is that it makes this property much more useful for consumers, who can actually rely on it to contain the resource name. The main risk as I see it (since we haven't identified a reason why this discrepancy is compelling), is backwards compat: maybe someone out there is relying on the current behavior in a way that would break under the "correct" behavior. |
Sorry for delayed response @madelson, I have been out sick for a while, I did some research about this issue to clear my doubt. The doc note below was the main cause of my doubt:
And the
Right, I would not expect many depend on this behavior, though it is somewhat breaking change, and I am not sure how acceptable this breaking change is. CC @tarekgh @ericstj @steveharter @joperezr. |
Appreciated the detailed response and investigation @buyaa-n . Sorry to hear that you were ill! |
* Make ResourceManager.BaseName work as documented. This property is documented to return the "qualified namespace name and the root resource name of a resource file". However, previously when constructing a ResourceManager with a Type the BaseName property would instead return the name of the type without its namespace. fix #74918 * Remove _locationInfo field * Add additional test cases for ResourceManager.BaseName. Address feedback from #75497 (comment). * Fix BaseName test case in response to #75497 (comment)
Description
According to the docs:
This is true when you access the generated
MyResource.ResourceManager.BaseName
property, which uses theResourceManager(baseName, assembly)
constructor.However, if you construct a
ResourceManager
with just aType
, it setsBaseName
toType.Name
which is different. The resource lookup still works because it uses the type's full name internally.Reproduction Steps
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 theBaseName
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.
The text was updated successfully, but these errors were encountered: