Title: Generic virtual method in baseclass causes InvalidProgramException · Issue #1776 · pythonnet/pythonnet · GitHub
Open Graph Title: Generic virtual method in baseclass causes InvalidProgramException · Issue #1776 · pythonnet/pythonnet
X Title: Generic virtual method in baseclass causes InvalidProgramException · Issue #1776 · pythonnet/pythonnet
Description: Environment Pythonnet version: 3.0.0-preview2022-04-11 Python version: 3.10 Operating System: MacOS and Ubuntu 2021.4 .NET Runtime: .net 6 Details If I create a python class which inherits from a C# class that has a virtual generic metho...
Open Graph Description: Environment Pythonnet version: 3.0.0-preview2022-04-11 Python version: 3.10 Operating System: MacOS and Ubuntu 2021.4 .NET Runtime: .net 6 Details If I create a python class which inherits from a C...
X Description: Environment Pythonnet version: 3.0.0-preview2022-04-11 Python version: 3.10 Operating System: MacOS and Ubuntu 2021.4 .NET Runtime: .net 6 Details If I create a python class which inherits from a C...
Opengraph URL: https://github.com/pythonnet/pythonnet/issues/1776
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Generic virtual method in baseclass causes InvalidProgramException","articleBody":"### Environment\r\n\r\n- Pythonnet version: 3.0.0-preview2022-04-11\r\n- Python version: 3.10\r\n- Operating System: MacOS and Ubuntu 2021.4\r\n- .NET Runtime: .net 6\r\n\r\n### Details\r\n\r\nIf I create a python class which inherits from a C# class that has a virtual generic method and exception is thrown while the class is being defined. Note, not during object instanciation time.\r\n\r\nTo reproduce, take the following C# class:\r\n```cs\r\n public abstract class GenericVirtualMethodTest\r\n {\r\n public virtual Q VirtMethod\u003cQ\u003e(Q arg1)\r\n {\r\n return arg1;\r\n }\r\n }\r\n```\r\n\r\nThen inherit from it as in this test:\r\n\r\n```py\r\ndef test_virtual_generic_method():\r\n class OverloadingSubclass(GenericVirtualMethodTest):\r\n __namespace__ = \"test_virtual_generic_method_cls\"\r\n obj = OverloadingSubclass()\r\n assert obj.VirtMethod[int](5) == 5\r\n```\r\n\r\nThe result is the following exception (Actually a C# exception inside a python exception inside a C# exception):\r\n```\r\nPython.Runtime.PythonException : An attempt was made to load a program with an incorrect format.\r\n (0x8007000B)\r\n File \"/Users/bruger/code/work/pythonnet/src/../tests/test_subclass.py\", line 268, in test_virtual_generic_method\r\n class OverloadingSubclass(GenericVirtualMethodTest):\r\n File \"\u003cstring\u003e\", line 19, in \u003cmodule\u003e\r\n at Python.Runtime.PythonException.ThrowLastAsClrException() in /Users/bruger/code/work/pythonnet/src/runtime/PythonException.cs:line 53\r\n at Python.Runtime.PythonException.ThrowIfIsNull(NewReference\u0026 ob) in /Users/bruger/code/work/pythonnet/src/runtime/PythonException.cs:line 455\r\n at Python.Runtime.PythonEngine.RunString(String code, BorrowedReference globals, BorrowedReference locals, RunFlagType flag) in /Users/bruger/code/work/pythonnet/src/runtime/PythonEngine.cs:line 625\r\n at Python.Runtime.PythonEngine.Exec(String code, PyDict globals, PyObject locals) in /Users/bruger/code/work/pythonnet/src/runtime/PythonEngine.cs:line 530\r\n at Python.PythonTestsRunner.PythonTestRunner.RunPythonTest(String testFile, String testName) in /Users/bruger/code/work/pythonnet/src/python_tests_runner/PythonTestRunner.cs:line 64\r\n-----\r\n\r\nOne or more child tests had errors\r\n Exception doesn't have a stacktrace\r\n```\r\n\r\n### Proposed Fix\r\n\r\nI understand that it is probably a bit complicated to actually override a virtual generic method in python code and maybe it is not even necesary. So maybe the best solution is to just ignore virtual methods in this case.\r\n\r\n\r\n","author":{"url":"https://github.com/rmadsen-ks","@type":"Person","name":"rmadsen-ks"},"datePublished":"2022-04-27T20:41:00.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":0},"url":"https://github.com/1776/pythonnet/issues/1776"}
| 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:1830c3fd-2221-f1e2-7d61-0bf4bac48695 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | ABB8:26EFB9:2D93E7F:3D8B99A:69707EB2 |
| html-safe-nonce | 49e379add41d70386027fa7ecc476c6212e421136f8361b500b1c2faaaa21ba0 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBQkI4OjI2RUZCOToyRDkzRTdGOjNEOEI5OUE6Njk3MDdFQjIiLCJ2aXNpdG9yX2lkIjoiNTQxNDEzMDQxMDk2ODg3NDY3NCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 109aae00d37659c40029d0c4f8b502c7305c185a784316fa440b4066c5b66f6d |
| hovercard-subject-tag | issue:1217861102 |
| 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/1776/issue_layout |
| twitter:image | https://opengraph.githubassets.com/1070cf98dd35842a86311bb8d2deb262a5fc56474891ccc68b7ccb7d10e447b1/pythonnet/pythonnet/issues/1776 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/1070cf98dd35842a86311bb8d2deb262a5fc56474891ccc68b7ccb7d10e447b1/pythonnet/pythonnet/issues/1776 |
| og:image:alt | Environment Pythonnet version: 3.0.0-preview2022-04-11 Python version: 3.10 Operating System: MacOS and Ubuntu 2021.4 .NET Runtime: .net 6 Details If I create a python class which inherits from a C... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | rmadsen-ks |
| hostname | github.com |
| expected-hostname | github.com |
| None | 9920a62ba22d06470388e2904804fb7e5ec51c9e35f81784e9191394c74b2bd2 |
| 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 | 7d6181066430cc06553c8396ca201e194ae33cb9 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width