Title: GitHub · Where software is built
Open Graph Title: pythonnet/pythonnet
X Title: pythonnet/pythonnet
Description: Python for .NET is a package that gives Python programmers nearly seamless integration with the .NET Common Language Runtime (CLR) and provides a powerful application scripting tool for .NET developers. - pythonnet/pythonnet
Open Graph Description: Python for .NET is a package that gives Python programmers nearly seamless integration with the .NET Common Language Runtime (CLR) and provides a powerful application scripting tool for .NET develo...
X Description: Python for .NET is a package that gives Python programmers nearly seamless integration with the .NET Common Language Runtime (CLR) and provides a powerful application scripting tool for .NET develo...
Opengraph URL: https://github.com/pythonnet/pythonnet
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Calling overridden method with out parameter from C# to python results in 0xC0000005 (Access Violation)","articleBody":"### Environment\r\n\r\n- Pythonnet version: 2.5.2\r\n- Python version: 3.8.3\r\n- Operating System: Win10 64bit\r\n- .NET Runtime: 4.8\r\n\r\n### Details\r\n\r\n- Describe what you were trying to get done.\r\n\r\nIn C# I have defined an interface with a method with an out parameter. I implemented this interface in python, an now I want to call this method from C#. (using pythonnet)\r\n\r\nWhat I see is that a method without out parameter works fine, but a method with an out parameter throws an access violation.\r\n\r\nI know that out parameters are handled differently in pythonnet: you return a tuple with first the return value and the second tuple item is the out parameter.\r\n\r\n- What commands did you run to trigger this issue? If you can provide a\r\n [Minimal, Complete, and Verifiable example](http://stackoverflow.com/help/mcve)\r\n this will help us understand the issue.\r\n\r\nMy C# code\r\n```C#\r\npublic interface IMyInterface\r\n{\r\n string MyMethod_Out(string name, out int index);\r\n string MyMethod(string name);\r\n}\r\n\r\npublic class MyServer\r\n{\r\n public void CallMyMethod_Out(IMyInterface myInterface)\r\n {\r\n Console.WriteLine(\"C#.CallMyMethod_Out: before MyMethod_Out\");\r\n int index = 1;\r\n myInterface.MyMethod_Out(\"myclient\", out index);\r\n Console.WriteLine($\"C#:CallMyMethod_Out: after MyMethod_Out: index:{index}\");\r\n }\r\n \r\n public void CallMyMethod(IMyInterface myInterface)\r\n {\r\n Console.WriteLine(\"C#.CallMyMethod: before MyMethod\");\r\n myInterface.MyMethod(\"myclient\");\r\n Console.WriteLine($\"C#:CallMyMethod: after MyMethod\");\r\n }\r\n\r\n public void DoSomething()\r\n {\r\n Console.WriteLine(\"C#.DoSomething\");\r\n }\r\n}\r\n```\r\n\r\nMy Python code:\r\n```python\r\nimport clr\r\nimport sys\r\n\r\nsys.path.append('some_dir')\r\nclr.AddReference(\"ClassLibrary1\")\r\n\r\nfrom ClassLibrary1 import IMyInterface, MyServer\r\n\r\nclass MyInterfaceImpl(IMyInterface):\r\n __namespace__ = \"ClassLibrary1\"\r\n\r\n def MyMethod_Out(self, name, index):\r\n print(\"Python.MyInterfaceImpl.MyMethod_Out\")\r\n other_index = 101\r\n return ('MyName', other_index)\r\n\r\n def MyMethod(self, name):\r\n print(\"Python.MyInterfaceImpl.MyMethod\")\r\n return 'MyName'\r\n\r\nprint('\\nCall regular C# function')\r\nmy_server = MyServer()\r\nmy_server.DoSomething()\r\n\r\nmy_interface_impl = MyInterfaceImpl()\r\n\r\nprint('\\nCall without out param')\r\nmy_server.CallMyMethod(my_interface_impl)\r\n\r\nprint('\\nCall with out param')\r\nmy_server.CallMyMethod_Out(my_interface_impl) # Access Violation 0xC0000005\r\n```\r\n\r\n- If there was a crash, please include the traceback here.\r\n**Output:**\r\n\r\n\u003e Call regular C# function\r\n\u003e C#.DoSomething\r\n\u003e \r\n\u003e Call without out param\r\n\u003e C#.CallMyMethod: before MyMethod\r\n\u003e Python.MyInterfaceImpl.MyMethod\r\n\u003e C#:CallMyMethod: after MyMethod\r\n\u003e \r\n\u003e Call with out param\r\n\u003e C#.CallMyMethod_Out: before MyMethod_Out\r\n\u003e Process finished with exit code -1073741819 (0xC0000005)\r\n\r\n**Expected output**\r\n\u003e ...\r\n\u003e Call with out param\r\n\u003e C#.CallMyMethod_Out: before MyMethod_Out\r\n\u003e Python.MyInterfaceImpl.MyMethod_Out\r\n\u003e C#:CallMyMethod_Out: after MyMethod_Out: index:101\r\n","author":{"url":"https://github.com/roy-van-de-korput","@type":"Person","name":"roy-van-de-korput"},"datePublished":"2021-07-05T13:19:15.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":5},"url":"https://github.com/1481/pythonnet/issues/1481"}
| route-pattern | /:user_id/:repository/issues/:id(.:format) |
| route-controller | issues |
| route-action | show |
| fetch-nonce | v2:90a7276a-02e4-456c-87b8-e6db0eb2a7b4 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C4B0:2835D5:26631AD:343CE12:6970938F |
| html-safe-nonce | 96becefc1a10b830fe9c62f1059db87aefd2dacab7aadab08a50b992853f4273 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDNEIwOjI4MzVENToyNjYzMUFEOjM0M0NFMTI6Njk3MDkzOEYiLCJ2aXNpdG9yX2lkIjoiODQwOTQ0Nzg4MzE2ODg0NjczNSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 8ec831dd481ac4d2ff3cc28aa288bbb60599475476ce697102ce4ec6ed897632 |
| hovercard-subject-tag | repository:14748123 |
| 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/pythonnet/pythonnet/issues/1481 |
| twitter:image | https://opengraph.githubassets.com/9c3eaa649f87ce8666e7f3954ab4d50595a3f98894df566864d36deadfbf2778/pythonnet/pythonnet |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/9c3eaa649f87ce8666e7f3954ab4d50595a3f98894df566864d36deadfbf2778/pythonnet/pythonnet |
| og:image:alt | Python for .NET is a package that gives Python programmers nearly seamless integration with the .NET Common Language Runtime (CLR) and provides a powerful application scripting tool for .NET develo... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | 9920a62ba22d06470388e2904804fb7e5ec51c9e35f81784e9191394c74b2bd2 |
| turbo-cache-control | no-cache |
| 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