vescon / MethodBoundaryAspect.Fody

A Fody weaver which allows to decorate methods and hook into method start, method end and method exceptions.
MIT License
243 stars 75 forks source link

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

Open hasanmanzak opened 1 year ago

hasanmanzak commented 1 year ago

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:

https://github.com/vescon/MethodBoundaryAspect.Fody/blob/1c94babb56aedcede20b1616f527576bac5a0579/src/MethodBoundaryAspect.Fody/InstructionBlockChainCreator.cs#L116-L117

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

https://github.com/vescon/MethodBoundaryAspect.Fody/blob/1c94babb56aedcede20b1616f527576bac5a0579/src/MethodBoundaryAspect.Fody/ReferenceFinder.cs#L22-L34

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.

Ralf1108 commented 1 year ago

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

hasanmanzak commented 1 year ago

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