-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
ComponentModel Category attribute with UseSystemResourceKeys is broken #49554
Comments
Tagging subscribers to this area: @safern Issue DetailsPublish and run the following application with and without UseSystemResourceKeys being set: <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>
</Project> using System;
using System.ComponentModel;
namespace BugRepro
{
class Program
{
static void Main()
{
Console.WriteLine(GetEnumCategory(AnEnum.Somthing));
}
public static string GetEnumCategory<T>(T enumValue)
where T : struct, IConvertible
{
if (!typeof(T).IsEnum)
return null;
var enumCategory = enumValue.ToString();
var fieldInfo = enumValue.GetType().GetField(enumValue.ToString());
if (fieldInfo != null)
{
var attrs = fieldInfo.GetCustomAttributes(typeof(CategoryAttribute), false);
if (attrs != null && attrs.Length > 0)
{
enumCategory = ((CategoryAttribute)attrs[0]).Category;
}
}
return enumCategory;
}
}
public enum AnEnum
{
[Category("SomthingCat")]
Somthing = 52,
}
}
The reason this happens is because of this code: Lines 170 to 182 in 82ca681
If Line 200 in 82ca681
This is looking for resources in our assembly named runtime/src/libraries/System.ComponentModel.Primitives/src/Resources/Strings.resx Lines 120 to 125 in 82ca681
One option is to turn
|
Tagging subscribers to 'linkable-framework': @eerhardt, @vitek-karas, @LakshanF, @tannergooding, @sbomer Issue DetailsPublish and run the following application with and without UseSystemResourceKeys being set: <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>
</Project> using System;
using System.ComponentModel;
namespace BugRepro
{
class Program
{
static void Main()
{
Console.WriteLine(GetEnumCategory(AnEnum.Somthing));
}
public static string GetEnumCategory<T>(T enumValue)
where T : struct, IConvertible
{
if (!typeof(T).IsEnum)
return null;
var enumCategory = enumValue.ToString();
var fieldInfo = enumValue.GetType().GetField(enumValue.ToString());
if (fieldInfo != null)
{
var attrs = fieldInfo.GetCustomAttributes(typeof(CategoryAttribute), false);
if (attrs != null && attrs.Length > 0)
{
enumCategory = ((CategoryAttribute)attrs[0]).Category;
}
}
return enumCategory;
}
}
public enum AnEnum
{
[Category("SomthingCat")]
Somthing = 52,
}
}
The reason this happens is because of this code: Lines 170 to 182 in 82ca681
If Line 200 in 82ca681
This is looking for resources in our assembly named runtime/src/libraries/System.ComponentModel.Primitives/src/Resources/Strings.resx Lines 120 to 125 in 82ca681
One option is to turn
|
We will follow your instruction and test it. Thanks |
Publish and run the following application with and without UseSystemResourceKeys being set:
The reason this happens is because of this code:
runtime/src/libraries/System.ComponentModel.Primitives/src/System/ComponentModel/CategoryAttribute.cs
Lines 170 to 182 in 82ca681
If
GetLocalizedString
returnsnull
,Category
just returns what was passed to the ctor. But ifGetLocalizedString
doesn't returnnull
, it uses what came fromGetLocalizedString
. Which looks like:runtime/src/libraries/System.ComponentModel.Primitives/src/System/ComponentModel/CategoryAttribute.cs
Line 200 in 82ca681
This is looking for resources in our assembly named
PropertyCategoryXXX
whereXXX
is the category name. For example:runtime/src/libraries/System.ComponentModel.Primitives/src/Resources/Strings.resx
Lines 120 to 125 in 82ca681
One option is to turn
UseSystemResourceKeys
off for this assembly. Or we could try to change the code somehow to do something different whenUseSystemResourceKeys=true
.The text was updated successfully, but these errors were encountered: