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

How to debug/get more info about `Sequence contains no matching element` error? #112

Open marceln opened 1 year ago

marceln commented 1 year ago

How could I get more info about which method/class is causing this exception:

Error       Fody: An unhandled exception occurred:
Exception:
Failed to execute weaver MethodBoundaryAspect.Fody.2.0.148\build\..\weaver\MethodBoundaryAspect.Fody.dll
Type:
System.Exception
StackTrace:
   at InnerWeaver.ExecuteWeavers() in C:\projects\fody\FodyIsolated\InnerWeaver.cs:line 222
   at InnerWeaver.Execute() in C:\projects\fody\FodyIsolated\InnerWeaver.cs:line 113
Source:
FodyIsolated
TargetSite:
Void ExecuteWeavers()
Sequence contains no matching element
Type:
System.InvalidOperationException
StackTrace:
   at System.Linq.Enumerable.Single[TSource](IEnumerable`1 source, Func`2 predicate)
   at MethodBoundaryAspect.Fody.InstructionBlockChainCreator.CreateMethodExecutionArgsInstance(NamedInstructionBlockChain argumentsArrayChain, TypeReference anyAspectTypeDefinition, MethodDefinition method, MethodInfoCompileTimeWeaver methodInfoCompileTimeWeaver)
   at MethodBoundaryAspect.Fody.MethodWeaver.WeaveMethodExecutionArgs(NamedInstructionBlockChain arguments)
   at MethodBoundaryAspect.Fody.MethodWeaver.Weave()
   at MethodBoundaryAspect.Fody.ModuleWeaver.WeaveMethod(ModuleDefinition module, MethodDefinition method, List`1 aspectInfos, MethodInfoCompileTimeWeaver methodInfoCompileTimeWeaver)
   at MethodBoundaryAspect.Fody.ModuleWeaver.WeaveType(ModuleDefinition module, TypeDefinition type, Collection`1 assemblyMethodBoundaryAspects)
   at MethodBoundaryAspect.Fody.ModuleWeaver.WeaveTypeAndNestedTypes(ModuleDefinition module, TypeDefinition type, Collection`1 assemblyMethodBoundaryAspects)
   at MethodBoundaryAspect.Fody.ModuleWeaver.Execute(ModuleDefinition module)
   at InnerWeaver.ExecuteWeavers() in C:\projects\fody\FodyIsolated\InnerWeaver.cs:line 186
Source:
System.Core
TargetSite:
TSource Single[TSource](System.Collections.Generic.IEnumerable`1[TSource], System.Func`2[TSource,System.Boolean])   
Ralf1108 commented 1 year ago

On which scope did you apply the attribute ? Assembly, class or method? Try to reduce the methods which are weaved by applying the attribute only on class level and then at method level one by one.

It would be good if you can narrow it down and show the C# Code which triggers this exception.

Ralf1108 commented 1 year ago

According to the stack trace in class "InstructionBlockChainCreator" there are on 2 "Single()" calls so it seems that somehow the "OnEntry" method in your aspect has an unexpected signature.

Can you also post your aspect class here? (method bodies are not important only the method headers)