-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Closed
Labels
area-System.ReflectionquestionAnswer questions and provide assistance, not an issue with source code or documentation.Answer questions and provide assistance, not an issue with source code or documentation.
Description
Description
I have a code that loads an assembly and using custom attributes to categorize data.
I'm trying to get the actual CustomAttribute object for some interfaces which have the requested Attribute.
on net framework48, the code returns the Attribute value as expected.
during migration to .Net5 - Running the code on .Net5 returns null.
I tried few overloads with no luck.
Reproduction Steps
A custom attribute:
[AttributeUsage(AttributeTargets.Interface)]
public class ApiInterfaceDescriptorAttribute : Attribute
{
public string ApiUsageName { get; }
public ApiInterfaceDescriptorAttribute(string apiUsageName)
{
ApiUsageName = apiUsageName;
}
}
Sample interface:
[ApiInterfaceDescriptor("powercontrol")]
public interface IMyInterface
{
[ApiMethodDescriptor(ApiExposureLevel.Basic, "a-method...")]
void SomeMethod();
}
usage:
public void GetApi()
{
var assembly = Assembly.LoadFile("MyFile");
var myInterface = assembly.DefinedTypes.FirstOrDefault(...) // get the interface
var att = myInterface.GetCustomAttribute(typeof(ApiInterfaceDescriptorAttribute));// returns null on Net5 and value on net48
var att = myInterface.GetCustomAttribute<ApiInterfaceDescriptorAttribute>();// returns null on Net5
}
Expected behavior
return the requested attribute
Actual behavior
method returns null
Regression?
No response
Known Workarounds
Read the CustomAtrributes object[] and itterate and query the requested attribute
Configuration
Running on Win10 x64, .Net5
Other information
No response
Metadata
Metadata
Assignees
Labels
area-System.ReflectionquestionAnswer questions and provide assistance, not an issue with source code or documentation.Answer questions and provide assistance, not an issue with source code or documentation.