MethodBoundaryAspect.Fody icon indicating copy to clipboard operation
MethodBoundaryAspect.Fody copied to clipboard

C#11 introduce Attribute with Generics. Do you have any plan?

Open gioce90 opened this issue 3 years ago • 5 comments
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()
	{
		//...
	}
}

gioce90 avatar May 31 '22 17:05 gioce90

Ah, didn't know about this new feature.

What is the exception about? Thrown at weaving or execution time?

Ralf1108 avatar May 31 '22 20:05 Ralf1108

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

gioce90 avatar Jun 01 '22 13:06 gioce90