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

InvalidOperationException is thrown by .Single call when there's an aspect inheritance #120

Open
hasanmanzak opened this issue Sep 3, 2023 · 2 comments · May be fixed by #121
Open

InvalidOperationException is thrown by .Single call when there's an aspect inheritance #120

hasanmanzak opened this issue Sep 3, 2023 · 2 comments · May be fixed by #121

Comments

@hasanmanzak
Copy link

InvalidOperationException: Sequence contains no matching element exception is thrown when I create another inheritable class from OnMethodBoundaryAspect:

public abstract class MethodBoundaryAspect : OnMethodBoundaryAspect
{
   // some stuff
}

public class Log: MethodBoundaryAspect 
{
   // some other stuff
}

Offending lines:

var onEntryMethodTypeRef =
anyAspectTypeDefinition.Resolve().BaseType.Resolve().Methods.Single(AspectMethodCriteria.IsOnEntryMethod);

That approach forces the inheritance to have only single descendent. But through out the source that is solved with

public MethodReference GetMethodReference(TypeReference typeReference, Func<MethodDefinition, bool> predicate)
{
var typeDefinition = typeReference.Resolve();
MethodDefinition methodDefinition;
do
{
methodDefinition = typeDefinition.Methods.FirstOrDefault(predicate);
typeDefinition = typeDefinition.BaseType?.Resolve();
} while (methodDefinition == null && typeDefinition != null);
return _moduleDefinition.ImportReference(methodDefinition);
}

Yes, it can be done by mimicing that approach, but not importing the reference, in chain creator but using an already provided api is much cleaner, I suppose..

I'll be opening a PR for this, if that's ok.

@hasanmanzak hasanmanzak linked a pull request Sep 3, 2023 that will close this issue
@Ralf1108
Copy link
Collaborator

Ralf1108 commented Sep 4, 2023

Nice catch !
Could you provide a unittest/repo to avoid future regression bugs?

@hasanmanzak
Copy link
Author

Yes, of course! I'll be adding to my repo related to pr.

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

Successfully merging a pull request may close this issue.

2 participants