I have a code that loads an assembly and categorize data by attributes.
I'm trying to get the actual CustomAttribute object. during debug locally the code returns a value (code compiles to .Net5 and net48)
but during runtime on a remote machine on (.Net5 target) the code returns null when i call GetCustomAttributes.
The 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();
}
The trial to get the attribute
public class ApiDetector
{
private Dictionary<Type, List<MethodInfo>> _apiDictionary = new Dictionary<Type, List<MethodInfo>>();
public void LoadApiElements()
{
var apiKeyDesriptor = key.GetCustomAttribute(typeof(ApiInterfaceDescriptorAttribute)) as ApiInterfaceDescriptorAttribute;
_apiDetector.Add(new ApiDataObjectDescriptor { Name = key.Name, ApiUsageName = apiKeyDesriptor?.ApiUsageName, Type = key });
}
}
when i ran this code locally i get the instance:
Running the code on .Net5 remote machine returns null:
Any help will be welcome. Thanks ahead!
Aucun commentaire:
Enregistrer un commentaire