MethodBoundaryAspect.Fody
MethodBoundaryAspect.Fody copied to clipboard
C#11 introduce Attribute with Generics. Do you have any plan?
trafficstars
C#11 introduce Attribute with Generics. Do you have any plan to introduce this feature?
Actually this doesn't work:
public class MyWrapperAttribute<T> : OnMethodBoundaryAspect
{
private ILogger<T> _logger { get; set; }
public MyWrapperAttribute(ILogger<T> logger)
{
_logger = logger;
}
// onEntry and onExit methods just do some logging stuff before and after the execution of the "DoSomeWork" method ...
}
public class MyMethod
{
private ILogger<MyMethod> _myMethodLogger { get; set; }
public MyMethod(ILogger<MyMethod> logger)
{
_myMethodLogger = logger;
}
[MyWrapper<MyMethod>]
public async Task DoSomeWork()
{
//...
}
}
Ah, didn't know about this new feature.
What is the exception about? Thrown at weaving or execution time?
Ah, didn't know about this new feature.
What is the exception about? Thrown at weaving or execution time?
Hi,
At execution time, there is an System.InvalidOperationException when it tries to run the DoSomeWork() method.
Here a stacktrace from my real solution:
System.InvalidOperationException
HResult=0x80131509
Message=Could not execute the method because either the method itself or the containing type is not fully instantiated.
Source=My.Company.Designer
StackTrace:
at My.Company.Designer.ApiMethodInterceptorAttribute`1..ctor() in C:\Users\GPIAZZO\source\repos\MyBot\My.Company.Designer\Extensions\ApiMethodInterceptorAttribute.cs:line 85
at My.Company.Designer.APIMethod.AddNumberToCollectApiMethod.ExecuteAsync(ITurnContext context, String[] parameters)
at My.Company.Designer.Tests.APIMethodsTests.AddNumberToCollectApiMethodTest.<AddNumberToCollectApiMethodTest_Success_YES>d__4.MoveNext() in C:\Users\GPIAZZO\source\repos\MyBot\Tests\My.Company.Designer.Tests\APIMethodsTests\AddNumberToCollectApiMethodTest.cs:line 48