Skip to content

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

@hasanmanzak

Description

@hasanmanzak

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions