Title: Exception thrown when calling a parameterless constructor that has overload with at least one parameter and `params` · Issue #1302 · pythonnet/pythonnet · GitHub
Open Graph Title: Exception thrown when calling a parameterless constructor that has overload with at least one parameter and `params` · Issue #1302 · pythonnet/pythonnet
X Title: Exception thrown when calling a parameterless constructor that has overload with at least one parameter and `params` · Issue #1302 · pythonnet/pythonnet
Description: Environment Pythonnet version: master@c81c3c3db7fcc403d5f4e8298b320240829daab2 Python version: 3.7, 3.9 (both x64) Operating System: Windows Details This is a regression introduced in c81c3c3 . If there is a parameterless constructor (an...
Open Graph Description: Environment Pythonnet version: master@c81c3c3db7fcc403d5f4e8298b320240829daab2 Python version: 3.7, 3.9 (both x64) Operating System: Windows Details This is a regression introduced in c81c3c3 . If ...
X Description: Environment Pythonnet version: master@c81c3c3db7fcc403d5f4e8298b320240829daab2 Python version: 3.7, 3.9 (both x64) Operating System: Windows Details This is a regression introduced in c81c3c3 . If ...
Opengraph URL: https://github.com/pythonnet/pythonnet/issues/1302
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Exception thrown when calling a parameterless constructor that has overload with at least one parameter and `params`","articleBody":"### Environment\r\n\r\n- Pythonnet version: master@c81c3c3db7fcc403d5f4e8298b320240829daab2\r\n- Python version: 3.7, 3.9 (both x64)\r\n- Operating System: Windows\r\n\r\n### Details\r\nThis is a regression introduced in c81c3c3db7fcc403d5f4e8298b320240829daab2 .\r\n\r\n- If there is a parameterless constructor (and probably a method too) that has an overload with at least one parameter `params` parameter, when called from Python, an InvalidIndexError will be raised from Python for .NET.\r\n\r\nCallstack from when called from within Unity\r\n```\r\nSystem.ArgumentOutOfRangeException : Index was out of range. Must be non-negative and less than the size of the collection.\r\nParameter name: index\r\n---\r\nat System.Collections.ArrayList.get_Item (System.Int32 index) [0x0001c] in \u003c437ba245d8404784b9fbab9b439ac908\u003e:0 \r\n at Python.Runtime.MethodBinder.TryConvertArguments (System.Reflection.ParameterInfo[] pi, System.Boolean paramsArray, System.IntPtr args, System.Int32 pyArgCount, System.Collections.Generic.Dictionary`2[TKey,TValue] kwargDict, System.Collections.ArrayList defaultArgList, System.Boolean needsResolution, System.Int32\u0026 outs) [0x0008a] in \u003cd0b807c6e27c43ea84a0e3a3c643e888\u003e:0 \r\n at Python.Runtime.MethodBinder.Bind (System.IntPtr inst, System.IntPtr args, System.IntPtr kw, System.Reflection.MethodBase info, System.Reflection.MethodInfo[] methodinfo) [0x0017c] in \u003cd0b807c6e27c43ea84a0e3a3c643e888\u003e:0 \r\n at Python.Runtime.MethodBinder.Bind (System.IntPtr inst, System.IntPtr args, System.IntPtr kw, System.Reflection.MethodBase info) [0x00000] in \u003cd0b807c6e27c43ea84a0e3a3c643e888\u003e:0 \r\n at Python.Runtime.ConstructorBinder.InvokeRaw (System.IntPtr inst, System.IntPtr args, System.IntPtr kw, System.Reflection.MethodBase info) [0x00074] in \u003cd0b807c6e27c43ea84a0e3a3c643e888\u003e:0 \r\n at Python.Runtime.ConstructorBinder.InvokeRaw (System.IntPtr inst, System.IntPtr args, System.IntPtr kw) [0x00000] in \u003cd0b807c6e27c43ea84a0e3a3c643e888\u003e:0 \r\n at Python.Runtime.ClassObject.tp_new (System.IntPtr tp, System.IntPtr args, System.IntPtr kw) [0x000b5] in \u003cd0b807c6e27c43ea84a0e3a3c643e888\u003e:0 \r\n at Python.Runtime.NativeCall.Call_3 (System.IntPtr fp, System.IntPtr a1, System.IntPtr a2, System.IntPtr a3) [0x00006] in \u003cd0b807c6e27c43ea84a0e3a3c643e888\u003e:0 \r\n at Python.Runtime.MetaType.tp_call (System.IntPtr tp, System.IntPtr args, System.IntPtr kw) [0x00024] in \u003cd0b807c6e27c43ea84a0e3a3c643e888\u003e:0 \r\n at (wrapper managed-to-native) Python.Runtime.Runtime.PyRun_String(string,Python.Runtime.RunFlagType,intptr,intptr)\r\n```\r\n\r\nI have a patch to show how to reproduce it (although it crashes pytest)\r\n```\r\ndiff --git a/src/testing/constructortests.cs b/src/testing/constructortests.cs\r\nindex 8800c94..ecc61ce 100644\r\n--- a/src/testing/constructortests.cs\r\n+++ b/src/testing/constructortests.cs\r\n@@ -48,4 +48,22 @@ namespace Python.Test\r\n value = v;\r\n }\r\n }\r\n+\r\n+ public class MultipleConstructorsTest\r\n+ {\r\n+ public string value;\r\n+ public Type[] type;\r\n+\r\n+ public MultipleConstructorsTest()\r\n+ {\r\n+ value = \"\";\r\n+ type = new Type[1] { null };\r\n+ }\r\n+\r\n+ public MultipleConstructorsTest(string s, params Type[] tp)\r\n+ {\r\n+ value = s;\r\n+ type = tp;\r\n+ }\r\n+ }\r\n }\r\ndiff --git a/src/tests/test_constructors.py b/src/tests/test_constructors.py\r\nindex 5e54896..c305377 100644\r\n--- a/src/tests/test_constructors.py\r\n+++ b/src/tests/test_constructors.py\r\n@@ -44,3 +44,12 @@ def test_subclass_constructor():\r\n instance = Sub()\r\n ob = SubclassConstructorTest(instance)\r\n assert isinstance(ob.value, System.Exception)\r\n+\r\n+\r\n+def test_multiple_constructor():\r\n+ from Python.Test import MultipleConstructorsTest\r\n+ import System\r\n+\r\n+ # Test parameterless\r\n+ ob = MultipleConstructorsTest()\r\n+ assert ob.value == \"\"\r\n\r\n```\r\n","author":{"url":"https://github.com/BadSingleton","@type":"Person","name":"BadSingleton"},"datePublished":"2020-12-03T19:39:52.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":0},"url":"https://github.com/1302/pythonnet/issues/1302"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:fd3c84b7-75eb-3067-fc29-02932a21de9c |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | E3C6:19782E:3066FF:3F4A32:69702DDA |
| html-safe-nonce | 4497ef83da7eb0572c3d4e185f867b1bafb125dd1df985702074ebb36afdfe21 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFM0M2OjE5NzgyRTozMDY2RkY6M0Y0QTMyOjY5NzAyRERBIiwidmlzaXRvcl9pZCI6IjYwOTY5NTI2NDgyMTg0NTU1MTQiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 03f32a3998b25704ed0138917edd0779d35d94f20e2cc758d549f234a948c755 |
| hovercard-subject-tag | issue:756519011 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/pythonnet/pythonnet/1302/issue_layout |
| twitter:image | https://opengraph.githubassets.com/aeaa7815312e1d92c50b75f3325ae3d7778b1b3286365d87155458160ebf973e/pythonnet/pythonnet/issues/1302 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/aeaa7815312e1d92c50b75f3325ae3d7778b1b3286365d87155458160ebf973e/pythonnet/pythonnet/issues/1302 |
| og:image:alt | Environment Pythonnet version: master@c81c3c3db7fcc403d5f4e8298b320240829daab2 Python version: 3.7, 3.9 (both x64) Operating System: Windows Details This is a regression introduced in c81c3c3 . If ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | BadSingleton |
| hostname | github.com |
| expected-hostname | github.com |
| None | 01fa379f5de85ef8e791d09724e69709ce9eb9595278316e0a921312dc88e0bc |
| turbo-cache-control | no-preview |
| go-import | github.com/pythonnet/pythonnet git https://github.com/pythonnet/pythonnet.git |
| octolytics-dimension-user_id | 6050430 |
| octolytics-dimension-user_login | pythonnet |
| octolytics-dimension-repository_id | 14748123 |
| octolytics-dimension-repository_nwo | pythonnet/pythonnet |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 14748123 |
| octolytics-dimension-repository_network_root_nwo | pythonnet/pythonnet |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | dda91974c069382b0dfa47b2da7e28bd061c8331 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width