Closed Dhairya-Sangoi closed 6 years ago
Hi,
yes I will look into this. Can you provide me with your TestProject if possible please. This error looks a lot like the optimized out parameter references in the AsyncStateMachine.
Hey, it wont be possible for me to share the code, as it would be against my company's policy!
Let me try to repro it in some test solution and share that with you if possible
Cool thanks... That would help me a lot.
I am unable to repro it in a test solution. Some more info about the bug:
Library B, and Project A both use attribute which implements IMethodInterceptor.
When a rebuild of project A is triggered, the Library B is weaved successfully and project A is also weaved but it fails. When a rebuild of the solution is triggered, only project A is weaved successfully. Library B isn't weaved.
Hope this helps to narrow down the issue!
I am able to repro using the above solution. Below are the logs for the same:
1> Fody/Cauldron.Interception: -----------------------------------------------------------------------------
1> Fody/Cauldron.Interception: Cauldron Interception v3.0.0.26
1> Fody/Cauldron.Interception: ----- Implementing decorator interceptors took 2.6241ms -----
1> Fody/Cauldron.Interception: Found Custom interceptors
1> Fody/Cauldron.Interception: - c:\users\dhsangoi\Source\Repos\Cauldron3026Testing\CauldronClassLibrary\Interceptors\Cauldron.BasicInterceptors-3.0.0.26.dll
1> Fody/Cauldron.Interception: Finding attributes took 1.9552ms
1> Fody/Cauldron.Interception: >> Executing custom interceptors in: Anonymous Type To Interface
1> Fody/Cauldron.Interception: Executing custom interceptor: Anonymous Type To Interface
1> Fody/Cauldron.Interception: ----- Implementing Anonymous Type To Interface interceptors took 117.6334ms -----
1> Fody/Cauldron.Interception: >> Executing custom interceptors in: Constructor Interceptors
1> Fody/Cauldron.Interception: Executing custom interceptor: Constructor Interception
1> Fody/Cauldron.Interception: ----- Implementing Constructor Interceptors interceptors took 56.2494ms -----
1> Fody/Cauldron.Interception: >> Executing custom interceptors in: Field Interceptors
1> Fody/Cauldron.Interception: Executing custom interceptor: Field Interception
1> Fody/Cauldron.Interception: ----- Implementing Field Interceptors interceptors took 87.2233ms -----
1> Fody/Cauldron.Interception: >> Executing custom interceptors in: Method Interceptors
1> Fody/Cauldron.Interception: Executing custom interceptor: Type-Wide Method Interception
1> Fody/Cauldron.Interception: Executing custom interceptor: Method Interception
1> Fody/Cauldron.Interception: Implementing method interceptors: ConsoleInterceptedClass TaskStringFunction()
1> Fody/Cauldron.Interception: ---> 'System.Threading.Tasks.Task`1<TResult> System.Threading.Tasks.Task::FromResult<System.String>(TResult)' resolving 'TResult'
1> Fody/Cauldron.Interception: Implementing method interceptors: ConsoleInterceptedClass TaskFunction()
1> Fody/Cauldron.Interception: ---> 'System.Threading.Tasks.Task`1<TResult> System.Threading.Tasks.Task::FromResult<System.Int32>(TResult)' resolving 'TResult'
1> Fody/Cauldron.Interception: Implementing method interceptors: ConsoleInterceptedClass AsyncStringFunction()
1> Fody/Cauldron.Interception: Implementing method interceptors: ConsoleInterceptedClass AsyncVoidFunction()
1> Fody/Cauldron.Interception: Implementing method interceptors: ConsoleInterceptedClass AsyncTaskFunction()
1> Fody/Cauldron.Interception: Implementing method interceptors: ConsoleInterceptedClass StringFunction(String, Int32, Object)
1> Fody/Cauldron.Interception: Implementing method interceptors: ConsoleInterceptedClass VoidFunction()
1> Fody/Cauldron.Interception: ----- Implementing Method Interceptors interceptors took 618.7817ms -----
1> Fody/Cauldron.Interception: >> Executing custom interceptors in: Property Interceptors
1> Fody/Cauldron.Interception: Executing custom interceptor: Type-Wide Property Interception
1> Fody/Cauldron.Interception: Executing custom interceptor: Property Interception
1> Fody/Cauldron.Interception: ----- Implementing Property Interceptors interceptors took 202.0936ms -----
1> Fody/Cauldron.Interception: >> Executing custom interceptors in: AssignMethodAttributeInfo
1> Fody/Cauldron.Interception: ----- Implementing AssignMethodAttributeInfo interceptors took 0.1114ms -----
1> Fody/Cauldron.Interception: >> Executing custom interceptors in: InterceptorInfo
1> Fody/Cauldron.Interception: ----- Implementing InterceptorInfo interceptors took 0.0504ms -----
1> Fody/Cauldron.Interception: >> Executing custom interceptors in: ModuleWeaver
1> Fody/Cauldron.Interception: ----- Implementing ModuleWeaver interceptors took 0.02ms -----
1> Fody/Cauldron.Interception: ----- Implementing custom interceptors interceptors took 1341.65ms -----
1> Fody/Cauldron.Interception: ----- Implementing ModuleLoad interceptors took 3.8481ms -----
1> Fody: Finished Fody 2355ms.
1>CauldronClassLibrary -> CauldronClassLibrary\bin\Debug\netstandard2.0\CauldronClassLibrary.dll
1> Fody: Skipped Verifying assembly since it is disabled in configuration
2>------ Rebuild All started: Project: CauldronConsoleApp, Configuration: Debug Any CPU ------
2> Fody: Fody (version 3.0.3.0) Executing
2> Fody/Cauldron.Interception: -----------------------------------------------------------------------------
2> Fody/Cauldron.Interception: Cauldron Interception v3.0.0.26
2> Fody/Cauldron.Interception: ----- Implementing decorator interceptors took 0.2309ms -----
2> Fody/Cauldron.Interception: Found Custom interceptors
2> Fody/Cauldron.Interception: - c:\users\dhsangoi\Source\Repos\Cauldron3026Testing\CauldronConsoleApp\Interceptors\Cauldron.BasicInterceptors-3.0.0.26.dll
2> Fody/Cauldron.Interception: Finding attributes took 0.0648ms
2> Fody/Cauldron.Interception: >> Executing custom interceptors in: Anonymous Type To Interface
2> Fody/Cauldron.Interception: Executing custom interceptor: Anonymous Type To Interface
2> Fody/Cauldron.Interception: ----- Implementing Anonymous Type To Interface interceptors took 7.5939ms -----
2> Fody/Cauldron.Interception: >> Executing custom interceptors in: Constructor Interceptors
2> Fody/Cauldron.Interception: Executing custom interceptor: Constructor Interception
2> Fody/Cauldron.Interception: ----- Implementing Constructor Interceptors interceptors took 30.4502ms -----
2> Fody/Cauldron.Interception: >> Executing custom interceptors in: Field Interceptors
2> Fody/Cauldron.Interception: Executing custom interceptor: Field Interception
2> Fody/Cauldron.Interception: ----- Implementing Field Interceptors interceptors took 193.1502ms -----
2> Fody/Cauldron.Interception: >> Executing custom interceptors in: Method Interceptors
2> Fody/Cauldron.Interception: Executing custom interceptor: Type-Wide Method Interception
2> Fody/Cauldron.Interception: Executing custom interceptor: Method Interception
2> Fody/Cauldron.Interception: Implementing method interceptors: LibraryInterceptedClass TaskStringFunction()
2> Fody/Cauldron.Interception: ---> 'System.Threading.Tasks.Task`1<TResult> System.Threading.Tasks.Task::FromResult<System.String>(TResult)' resolving 'TResult'
2> Fody/Cauldron.Interception: Implementing method interceptors: LibraryInterceptedClass TaskFunction()
2> Fody/Cauldron.Interception: ---> 'System.Threading.Tasks.Task`1<TResult> System.Threading.Tasks.Task::FromResult<System.Int32>(TResult)' resolving 'TResult'
2> Fody/Cauldron.Interception: Implementing method interceptors: LibraryInterceptedClass AsyncStringFunction()
2> Fody/Cauldron.Interception: ----- Implementing Method Interceptors interceptors took 333.349ms -----
2> Fody/Cauldron.Interception: ----- Implementing custom interceptors interceptors took 586.7506ms -----
2>MSBUILD : error : Fody: An unhandled exception occurred:
2>MSBUILD : error : Exception:
2>MSBUILD : error : Failed to execute weaver C:\Users\dhsangoi\.nuget\packages\cauldron.interception.fody\3.0.26\netclassicweaver\Cauldron.Interception.Fody.dll
2>MSBUILD : error : Type:
2>MSBUILD : error : System.Exception
2>MSBUILD : error : StackTrace:
2>MSBUILD : error : at InnerWeaver.ExecuteWeavers()
2>MSBUILD : error : at InnerWeaver.Execute()
2>MSBUILD : error : Source:
2>MSBUILD : error : FodyIsolated
2>MSBUILD : error : TargetSite:
2>MSBUILD : error : Void ExecuteWeavers()
2>MSBUILD : error : Exception has been thrown by the target of an invocation.
2>MSBUILD : error : Type:
2>MSBUILD : error : System.Reflection.TargetInvocationException
2>MSBUILD : error : StackTrace:
2>MSBUILD : error : at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
2>MSBUILD : error : at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
2>MSBUILD : error : at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
2>MSBUILD : error : at Cauldron.Interception.Fody.ModuleWeaver.ExecuteInterceptionScripts(Builder builder)
2>MSBUILD : error : at Cauldron.Interception.Fody.ModuleWeaver.OnExecute()
2>MSBUILD : error : at Cauldron.Interception.Cecilator.WeaverBase.Execute()
2>MSBUILD : error : at InnerWeaver.ExecuteWeavers()
2>MSBUILD : error : Source:
2>MSBUILD : error : mscorlib
2>MSBUILD : error : TargetSite:
2>MSBUILD : error : System.Object InvokeMethod(System.Object, System.Object[], System.Signature, Boolean)
2>MSBUILD : error : Object reference not set to an instance of an object.
2>MSBUILD : error : Type:
2>MSBUILD : error : System.NullReferenceException
2>MSBUILD : error : StackTrace:
2>MSBUILD : error : at Cauldron.Interception.Cecilator.AsyncMethodHelper.GetAsyncStateMachineExceptionBlock()
2>MSBUILD : error : at Cauldron.Interception.Cecilator.AsyncStateMachinePositions..ctor(Method method)
2>MSBUILD : error : at Cauldron.Interception.Cecilator.Coders.Coder.OriginalBody(Boolean createNewMethod)
2>MSBUILD : error : at Weaver_Method.<>c__DisplayClass5_2.<InterceptMethods>b__19(Coder x)
2>MSBUILD : error : at Cauldron.Interception.Cecilator.Coders.Coder.Try(Func`2 code)
2>MSBUILD : error : at Weaver_Method.InterceptMethods(Builder builder)
2>MSBUILD : error : Source:
2>MSBUILD : error : Cauldron.Interception.Cecilator
2>MSBUILD : error : TargetSite:
2>MSBUILD : error : System.Tuple`2[Cauldron.Interception.Cecilator.Positions,Mono.Cecil.Cil.ExceptionHandler] GetAsyncStateMachineExceptionBlock()
2>MSBUILD : error :
2> Fody: Finished Fody 827ms.
I have removed the <
Hope this helps!
Btw, if we remove the attribute annotation from the imported library, then the console application importing this library weaves correctly.
OK thank you. I am debugging it right now.
I got the root cause... Cauldron was not able to detect if the method is async. This is because of the following: The attribute I am expecting is: System.Runtime.CompilerServices.AsyncStateMachineAttribute which would be in netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51 The attribute that is found resides in System.Runtime, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a This actually comes from the NetStandard - NetCore mix. It seems that the attribute now exist 2 times. I had the same issues with NetStandard and NetClassic. Here it is System.Runtime and mscorlib types which are loaded during weaving.
Can you try the following version please. I am afraid that the error in your test program hast nothing to do with the original exception.
Cauldron.Interception.Fody.zip Just replace the versions in v3.0.0.26.
Tried to use the dlls you gave. Now I am getting the following error:
2> Fody/Cauldron.Interception: Implementing method interceptors: SomeTestClass TestClassMethod()
2> Fody/Cauldron.Interception: ----- Implementing Method Interceptors interceptors took 3406.8055ms -----
2> Fody/Cauldron.Interception: ----- Implementing custom interceptors interceptors took 8083.396ms -----
2>MSBUILD : error : Fody: An unhandled exception occurred:
2>MSBUILD : error : Exception:
2>MSBUILD : error : Failed to execute weaver src\packages\Cauldron.Interception.Fody.3.0.26\netclassicweaver\Cauldron.Interception.Fody.dll
2>MSBUILD : error : Type:
2>MSBUILD : error : System.Exception
2>MSBUILD : error : StackTrace:
2>MSBUILD : error : at InnerWeaver.ExecuteWeavers()
2>MSBUILD : error : at InnerWeaver.Execute()
2>MSBUILD : error : Source:
2>MSBUILD : error : FodyIsolated
2>MSBUILD : error : TargetSite:
2>MSBUILD : error : Void ExecuteWeavers()
2>MSBUILD : error : Exception has been thrown by the target of an invocation.
2>MSBUILD : error : Type:
2>MSBUILD : error : System.Reflection.TargetInvocationException
2>MSBUILD : error : StackTrace:
2>MSBUILD : error : at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
2>MSBUILD : error : at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
2>MSBUILD : error : at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
2>MSBUILD : error : at Cauldron.Interception.Fody.ModuleWeaver.ExecuteInterceptionScripts(Builder builder)
2>MSBUILD : error : at Cauldron.Interception.Fody.ModuleWeaver.OnExecute()
2>MSBUILD : error : at Cauldron.Interception.Cecilator.WeaverBase.Execute()
2>MSBUILD : error : at InnerWeaver.ExecuteWeavers()
2>MSBUILD : error : Source:
2>MSBUILD : error : mscorlib
2>MSBUILD : error : TargetSite:
2>MSBUILD : error : System.Object InvokeMethod(System.Object, System.Object[], System.Signature, Boolean)
2>MSBUILD : error : Unable to detect current method:
2>MSBUILD : error : Name: TestClassMethod
2>MSBUILD : error : MoveNext: False
2>MSBUILD : error : IsAsyncStateMachine: False
2>MSBUILD : error : HasAsyncStateMachineAttribute: False
2>MSBUILD : error : Type:
2>MSBUILD : error : System.NullReferenceException
2>MSBUILD : error : StackTrace:
2>MSBUILD : error : at Cauldron.Interception.Cecilator.AsyncMethodHelper.get_MoveNextMethod()
2>MSBUILD : error : at Cauldron.Interception.Cecilator.AsyncMethodHelper.GetAsyncStateMachineExceptionBlock()
2>MSBUILD : error : at Cauldron.Interception.Cecilator.AsyncStateMachinePositions..ctor(Method method)
2>MSBUILD : error : at Cauldron.Interception.Cecilator.Coders.Coder.OriginalBody(Boolean createNewMethod)
2>MSBUILD : error : at Weaver_Method.<>c__DisplayClass5_2.<InterceptMethods>b__19(Coder x)
2>MSBUILD : error : at Cauldron.Interception.Cecilator.Coders.Coder.Try(Func`2 code)
2>MSBUILD : error : at Weaver_Method.InterceptMethods(Builder builder)
2>MSBUILD : error : Source:
2>MSBUILD : error : Cauldron.Interception.Cecilator
2>MSBUILD : error : TargetSite:
2>MSBUILD : error : Cauldron.Interception.Cecilator.Method get_MoveNextMethod()
2>MSBUILD : error :
2> Fody: Finished Fody 9299ms.
This error is in the actual project. I have just replaced the class and method names.
I guess its unable to detect the MoveNext method which is generated as a part of the async state machine.
Also, getting this error when used with an async method in the same classs. The difference between the previous method and this method is that this method has parameters.
2> Fody/Cauldron.Interception: Implementing method interceptors: SomeTestClass SomeTestMethod(String, Boolean)
2> Fody/Cauldron.Interception: ----- Implementing Method Interceptors interceptors took 3689.1404ms -----
2> Fody/Cauldron.Interception: ----- Implementing custom interceptors interceptors took 6835.3965ms -----
2>MSBUILD : error : Fody: An unhandled exception occurred:
2>MSBUILD : error : Exception:
2>MSBUILD : error : Failed to execute weaver src\packages\Cauldron.Interception.Fody.3.0.26\netclassicweaver\Cauldron.Interception.Fody.dll
2>MSBUILD : error : Type:
2>MSBUILD : error : System.Exception
2>MSBUILD : error : StackTrace:
2>MSBUILD : error : at InnerWeaver.ExecuteWeavers()
2>MSBUILD : error : at InnerWeaver.Execute()
2>MSBUILD : error : Source:
2>MSBUILD : error : FodyIsolated
2>MSBUILD : error : TargetSite:
2>MSBUILD : error : Void ExecuteWeavers()
2>MSBUILD : error : Exception has been thrown by the target of an invocation.
2>MSBUILD : error : Type:
2>MSBUILD : error : System.Reflection.TargetInvocationException
2>MSBUILD : error : StackTrace:
2>MSBUILD : error : at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
2>MSBUILD : error : at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
2>MSBUILD : error : at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
2>MSBUILD : error : at Cauldron.Interception.Fody.ModuleWeaver.ExecuteInterceptionScripts(Builder builder)
2>MSBUILD : error : at Cauldron.Interception.Fody.ModuleWeaver.OnExecute()
2>MSBUILD : error : at Cauldron.Interception.Cecilator.WeaverBase.Execute()
2>MSBUILD : error : at InnerWeaver.ExecuteWeavers()
2>MSBUILD : error : Source:
2>MSBUILD : error : mscorlib
2>MSBUILD : error : TargetSite:
2>MSBUILD : error : System.Object InvokeMethod(System.Object, System.Object[], System.Signature, Boolean)
2>MSBUILD : error : Object reference not set to an instance of an object.
2>MSBUILD : error : Type:
2>MSBUILD : error : System.NullReferenceException
2>MSBUILD : error : StackTrace:
2>MSBUILD : error : at Cauldron.Interception.Cecilator.Coders.Coder.GetParametersArray()
2>MSBUILD : error : at Weaver_Method.<>c__DisplayClass5_2.<InterceptMethods>b__19(Coder x)
2>MSBUILD : error : at Cauldron.Interception.Cecilator.Coders.Coder.Try(Func`2 code)
2>MSBUILD : error : at Weaver_Method.InterceptMethods(Builder builder)
2>MSBUILD : error : Source:
2>MSBUILD : error : Cauldron.Interception.Cecilator
2>MSBUILD : error : TargetSite:
2>MSBUILD : error : Cauldron.Interception.Cecilator.Coders.ParametersVariableCodeBlock GetParametersArray()
2>MSBUILD : error :
2> Fody: Finished Fody 8170ms.
I was unable to reproduce this. I tried a lot... That why I have to ask you for a favor. I added more information to the Exception. Can you please try this one out and post the build message. Thanks.
Cauldron.Interception.Fody.zip
This does not fix the error... I just need the info from the build message to track the root cause.
Sure. Let me try this out. Thanks for the help!
Does this error still persist?
Hey,
I am getting the following error when annotating using an attribute implementing
IMethodInterceptor
interface. Here is the error snippet:The strange part is, it works for most of the
async
methods, but fails for some. Theseasync
methods are members of a normal class (nothing fancy!). Also,removing
annotations from some of thepreviously working async methods
, andadding
the annotation on thepreviously failing async methods
, solves the problem forsome async
methods (not all though!).The build was also failing
3.0.18
nuget version hence upgraded to the latest3.0.26
nuget. Now the error message has changed, but it comes for the same methods.Could you please take a look into this?