IronLanguages / ironpython2

Implementation of the Python programming language for .NET Framework; built on top of the Dynamic Language Runtime (DLR).
http://ironpython.net
Apache License 2.0
1.07k stars 229 forks source link

ArgumentNullException thrown when underlying c# delegate throws an exception #776

Open JimmyHeartbreaker opened 3 years ago

JimmyHeartbreaker commented 3 years ago

Version: 2.7.10 .Net Framework 4.7.2

When throwing an exception inside a C# delegate the following error is occasionally thrown.

System.ArgumentNullException: Value cannot be null. Parameter name: del at System.Reflection.RuntimeReflectionExtensions.GetMethodInfo(Delegate del) at IronPython.Runtime.PythonDynamicStackFrame.GetMethod(CodeContext context, FunctionCode funcCode) at IronPython.Runtime.PythonDynamicStackFrame..ctor(CodeContext context, FunctionCode funcCode, Int32 line) at IronPython.Runtime.Operations.PythonOps.UpdateStackTrace(Exception e, CodeContext context, FunctionCode funcCode, Int32 line) at Microsoft.Scripting.Interpreter.ActionCallInstruction4.Run(InterpretedFrame frame) at Microsoft.Scripting.Interpreter.Interpreter.HandleException(InterpretedFrame frame, Exception exception) at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame) at Microsoft.Scripting.Interpreter.LightLambda.Run2[T0,T1,TRet](T0 arg0, T1 arg1) at Microsoft.Scripting.Interpreter.DynamicInstruction3.Run(InterpretedFrame frame) at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame) at Microsoft.Scripting.Interpreter.LightLambda.Run2[T0,T1,TRet](T0 arg0, T1 arg1) at IronPython.Compiler.PythonScriptCode.RunWorker(CodeContext ctx) at Microsoft.Scripting.Hosting.CompiledCode.Execute[T](ScriptScope scope)

It is difficult to reproduce because it is intermittent. We are caching the compiled script so it could be something at that stage. This would explain the intermittent behaviour the way we are seeing it.

it is important that we catch the correct exception in the c# calling Execute.

Not sure when this started happening. It wasnt happening in earlier versions. Nothing in our code explains this behaviour.

Would there be any reason 2.7.11 would not have this problem?

slozier commented 3 years ago

What version were you running on before? I can't think of any changes since the 2.7.10 release that might resolve this...

JimmyHeartbreaker commented 3 years ago

What version were you running on before? I can't think of any changes since the 2.7.10 release that might resolve this...

The last version before 2.7.10 was 2.7.7 I see the DLR version goes from 1.2.3 -> 1.3 in the 2.7.11 release.

slozier commented 3 years ago

There have been quite a few changes since 2.7.7 so without any code to reproduce the issue it's hard to say if/when a bug might have been introduced.

The major bump in the version number of the DLR is due to a breaking change (removal of zlib). I mean, you can try 2.7.11, but I can't think of any changes that would relate the stack trace above.

JimmyHeartbreaker commented 3 years ago

ill try to recreate a minimal application to reproduce it. Thanks.

JimmyHeartbreaker commented 3 years ago

There have been quite a few changes since 2.7.7 so without any code to reproduce the issue it's hard to say if/when a bug might have been introduced.

The major bump in the version number of the DLR is due to a breaking change (removal of zlib). I mean, you can try 2.7.11, but I can't think of any changes that would relate the stack trace above.

I struggled to get a minimal application reproducing the issue. I rolled back to 2.7.5 and that fixed the issue.

Dunge commented 1 year ago

I'm having the same issue with 2.7.12 on .NET6 on very rare scripts and I'm trying to find out what might cause it. Any idea?

Traceback (most recent call last):
  File "SwzDesign", line 494, in <module>
TypeError: Value cannot be null. (Parameter 'del')
---> System.ArgumentNullException: Value cannot be null. (Parameter 'del')
   at System.Reflection.RuntimeReflectionExtensions.GetMethodInfo(Delegate del)
   at IronPython.Runtime.PythonDynamicStackFrame.GetMethod(CodeContext context, FunctionCode funcCode)
   at IronPython.Runtime.PythonDynamicStackFrame..ctor(CodeContext context, FunctionCode funcCode, Int32 line)
   at IronPython.Runtime.Operations.PythonOps.UpdateStackTrace(Exception e, CodeContext context, FunctionCode funcCode, Int32 line)
   at main$493(Closure , PythonFunction )
   at <unnamed>(Closure , CodeContext , FunctionCode )
   at IronPython.Compiler.PythonScriptCode.RunWorker(CodeContext ctx)
   at PythonWorkflows.PythonWorkflowsEngine.RunWorkflowInternal(CompiledCode compiledCode, ScriptScope scriptScope) in /src/PythonWorkflows/PythonWorkflowsEngine.cs:line 197

The line pointed out in my .py file is the main() line.

JimmyHeartbreaker commented 1 year ago

My issue was fixed in version 3.4

On Wed, 23 Aug 2023, 01:00 Dunge, @.***> wrote:

I'm having the same issue with 2.7.12 on very rare scripts and I'm trying to find out what might cause it. Any idea?

Traceback (most recent call last): File "SwzDesign", line 494, in TypeError: Value cannot be null. (Parameter 'del') ---> System.ArgumentNullException: Value cannot be null. (Parameter 'del') at System.Reflection.RuntimeReflectionExtensions.GetMethodInfo(Delegate del) at IronPython.Runtime.PythonDynamicStackFrame.GetMethod(CodeContext context, FunctionCode funcCode) at IronPython.Runtime.PythonDynamicStackFrame..ctor(CodeContext context, FunctionCode funcCode, Int32 line) at IronPython.Runtime.Operations.PythonOps.UpdateStackTrace(Exception e, CodeContext context, FunctionCode funcCode, Int32 line) at main$493(Closure , PythonFunction ) at (Closure , CodeContext , FunctionCode ) at IronPython.Compiler.PythonScriptCode.RunWorker(CodeContext ctx) at PythonWorkflows.PythonWorkflowsEngine.RunWorkflowInternal(CompiledCode compiledCode, ScriptScope scriptScope) in /src/JamLogic/PythonWorkflows/PythonWorkflowsEngine.cs:line 197

The line pointed out in my .py file is the main() line.

— Reply to this email directly, view it on GitHub https://github.com/IronLanguages/ironpython2/issues/776#issuecomment-1688588860, or unsubscribe https://github.com/notifications/unsubscribe-auth/AP6FO5GMXEFWK2B5JUIPSBLXWTQUBANCNFSM4X4IO4TA . You are receiving this because you authored the thread.Message ID: @.***>

Dunge commented 1 year ago

Cool. Any chance of getting the fix backported to IronPython2? I have too many existing python2 script to convert to IronPython3.

JimmyHeartbreaker commented 1 year ago

I'm sorry, i have no idea which change fixed it

On Wed, 23 Aug 2023, 09:26 Dunge, @.***> wrote:

Cool. Any chance of getting the fix backported to IronPython2? I have too many existing python2 script to convert to IronPython3.

— Reply to this email directly, view it on GitHub https://github.com/IronLanguages/ironpython2/issues/776#issuecomment-1689127034, or unsubscribe https://github.com/notifications/unsubscribe-auth/AP6FO5G2Z2ED5POTFA7ZEJDXWVL3ZANCNFSM4X4IO4TA . You are receiving this because you authored the thread.Message ID: @.***>