Weaving Exception on Async WinForm Event handlers
I am wanting to use this addin to support automatic logging using my logging framework. So far it works great except for this edge case.
Async WinForm event handlers have the signature of private async void SomeEvent( object sender )
This is an odd signature, notice they don't return Task, and I assume this is being treated as invalid.
These methods throw an InvalidOperationException during build as follows
Error Fody: An unhandled exception occurred:
Exception:
Failed to execute weaver F:\repositories\fabrica-script\packages\MethodBoundaryAspect.Fody.2.0.118\build..\weaver\MethodBoundaryAspect.Fody.dll
Type:
System.Exception
StackTrace:
at InnerWeaver.ExecuteWeavers() in C:\projects\fody\FodyIsolated\InnerWeaver.cs:line 206
at InnerWeaver.Execute() in C:\projects\fody\FodyIsolated\InnerWeaver.cs:line 111
Source:
FodyIsolated
TargetSite:
Void ExecuteWeavers()
Async state machine for System.Void Fabrica.Script.MainView::WhenRunCommandClicked(System.Object,DevExpress.XtraBars.ItemClickEventArgs) did not catch exceptions in the expected way.
Type:
System.InvalidOperationException
StackTrace:
at MethodBoundaryAspect.Fody.AsyncMethodWeaver.WeaveOnException(IList1 allAspects, Instruction instructionCallStart, Instruction instructionCallEnd, Instruction instructionAfterCall, IPersistable returnValue) at MethodBoundaryAspect.Fody.MethodWeaver.Weave() at MethodBoundaryAspect.Fody.ModuleWeaver.WeaveMethod(ModuleDefinition module, MethodDefinition method, List1 aspectInfos)
at MethodBoundaryAspect.Fody.ModuleWeaver.WeaveType(ModuleDefinition module, TypeDefinition type, Collection1 assemblyMethodBoundaryAspects) at MethodBoundaryAspect.Fody.ModuleWeaver.WeaveTypeAndNestedTypes(ModuleDefinition module, TypeDefinition type, Collection1 assemblyMethodBoundaryAspects)
at MethodBoundaryAspect.Fody.ModuleWeaver.Execute(ModuleDefinition module)
at MethodBoundaryAspect.Fody.ModuleWeaver.Execute()
at InnerWeaver.ExecuteWeavers() in C:\projects\fody\FodyIsolated\InnerWeaver.cs:line 178
Source:
MethodBoundaryAspect.Fody
TargetSite:
Void WeaveOnException(System.Collections.Generic.IList`1[MethodBoundaryAspect.Fody.AspectData], Mono.Cecil.Cil.Instruction, Mono.Cecil.Cil.Instruction, Mono.Cecil.Cil.Instruction, MethodBoundaryAspect.Fody.IPersistable) Fabrica.Script
Support for async was implemented by @keith-anders and we are not experienced enough to implement the IL Code for the async state machine. It seems that method with signature "async void" are not supported. I don't see a corresponding test in AsyncClass.cs.
Thanks for the response. I have seen you mention on other issues that @keith-anders is the person that did all the async stuff. I can't say I remember him chiming in on any of those issues. Is he still actively involved in the project?
I'm facing the same issue. Would be awesome if someone could provide a solution.