Skip to content
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

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

Open
gioce90 opened this issue May 31, 2022 · 5 comments
Open

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

gioce90 opened this issue May 31, 2022 · 5 comments

Comments

@gioce90
Copy link

gioce90 commented May 31, 2022

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()
	{
		//...
	}
}
@Ralf1108
Copy link
Collaborator

Ah, didn't know about this new feature.

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

@gioce90 gioce90 closed this as completed Jun 1, 2022
@gioce90
Copy link
Author

gioce90 commented Jun 1, 2022

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 gioce90 reopened this Jun 1, 2022
@gioce90
Copy link
Author

gioce90 commented Mar 3, 2023

Hi,

Have you some info about it?

@Ralf1108
Copy link
Collaborator

Ralf1108 commented Mar 6, 2023

Regarding C# language versioning the feature is only supported on .NET Core 7 or higher.

Currently MBA supports only "net462" and netstandard2.0". So we would have to make first the support for NET 7.0 at all and then support generic attribute usages for aspects

@gioce90
Copy link
Author

gioce90 commented Sep 28, 2023

Hi @Ralf1108
Are you planning to upgrade support to .NET7?
(or .NET8 which will be released in the next 2 months)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants