Title: Registering RawProxyEncoder Causes Stack Overflow · Issue #1427 · pythonnet/pythonnet · GitHub
Open Graph Title: Registering RawProxyEncoder Causes Stack Overflow · Issue #1427 · pythonnet/pythonnet
X Title: Registering RawProxyEncoder Causes Stack Overflow · Issue #1427 · pythonnet/pythonnet
Description: Environment Pythonnet version: installed from master branch on 30th March 2021 Python version: 3.9.2 Operating System: Windows 10 .NET Runtime: Microsoft.NETCore.App 5.0.4, Microsoft.WindowsDesktop.App 3.1.13 Summary Registering a RawPro...
Open Graph Description: Environment Pythonnet version: installed from master branch on 30th March 2021 Python version: 3.9.2 Operating System: Windows 10 .NET Runtime: Microsoft.NETCore.App 5.0.4, Microsoft.WindowsDesktop...
X Description: Environment Pythonnet version: installed from master branch on 30th March 2021 Python version: 3.9.2 Operating System: Windows 10 .NET Runtime: Microsoft.NETCore.App 5.0.4, Microsoft.WindowsDesktop...
Opengraph URL: https://github.com/pythonnet/pythonnet/issues/1427
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Registering RawProxyEncoder Causes Stack Overflow","articleBody":"### Environment\r\n\r\n- Pythonnet version: installed from master branch on 30th March 2021\r\n- Python version: 3.9.2\r\n- Operating System: Windows 10\r\n- .NET Runtime: Microsoft.NETCore.App 5.0.4, Microsoft.WindowsDesktop.App 3.1.13\r\n\r\n### Summary\r\nRegistering a `RawProxyEncoder` with `PyObjectConversions.RegisterEncoder()` causes the script to fail with a stack overflow.\r\n\r\n### Thanks\r\nFirst of all, I'd like to say thanks to everyone who's contributed to this project. It's incredibly useful for us to write one set of code to serve both .NET and Python developers. We've had very few problems with Pythonnet. Thanks very much.\r\n\r\n### Details\r\nI ran into a problem with Pythonnet converting System.Collections.Generic.List into a native python list as described in [issue 1153](https://github.com/pythonnet/pythonnet/issues/1153).\r\n\r\n[lostmsu](https://github.com/lostmsu) recommended using a RawProxyEncoder to disable the automatic conversion. Unfortunately, if I register an encoder and then call a .NET method the system crashes with a stack overflow.\r\n\r\n```python\r\nimport sys\r\nfrom pathlib import Path\r\nfrom clr_loader import get_coreclr\r\nfrom pythonnet import set_runtime\r\napi_path = Path('..\\\\PythonStubs\\\\bin\\\\Debug\\\\netcoreapp3.1')\r\nsys.path.append(str(api_path))\r\nrt = get_coreclr(runtime_config=str(api_path / f'PythonStubs.runtimeconfig.json'))\r\nset_runtime(rt)\r\nimport clr\r\nimport System\r\nfrom Python.Runtime import PyObjectConversions\r\nfrom Python.Runtime.Codecs import RawProxyEncoder\r\n\r\n\r\nclass ListAsRawEncoder(RawProxyEncoder):\r\n __namespace__ = 'Dummy'\r\n\r\n def CanEncode(self, clr_type):\r\n return clr_type.Name == 'IList`1' and clr_type.Namespace == 'System.Collections.Generic'\r\n\r\n\r\nif __name__ == '__main__':\r\n list_encoder = ListAsRawEncoder()\r\n PyObjectConversions.RegisterEncoder(list_encoder)\r\n\r\n domain = System.AppDomain.CurrentDomain\r\n print(\"Found\", domain.GetAssemblies().Length, \"assemblies in domain\")\r\n```\r\n\r\nThe output is:\r\n```\r\n Stack overflow\r\n```\r\n\r\nCommenting out the call to RegisterEncoder prevents the crash.","author":{"url":"https://github.com/richard-gemmell-42","@type":"Person","name":"richard-gemmell-42"},"datePublished":"2021-03-30T11:26:29.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":3},"url":"https://github.com/1427/pythonnet/issues/1427"}
| 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:e47c9d0f-934b-5d09-7d25-f32bab792b47 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 9A8A:1085F6:2EDDB9E:3F660B0:69708439 |
| html-safe-nonce | 14283546c0e683e9e1fb2530d5898f1439138e06c305fc26a8e375ae48b1420f |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5QThBOjEwODVGNjoyRUREQjlFOjNGNjYwQjA6Njk3MDg0MzkiLCJ2aXNpdG9yX2lkIjoiNzU5NDM5NDYxMDg3NjU4MDkyMSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 7e35cd1fb673bdce338f20a8ea9f29a031eea287d0c29fe6801a6f99f52dce86 |
| hovercard-subject-tag | issue:844400894 |
| 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/1427/issue_layout |
| twitter:image | https://opengraph.githubassets.com/1783d69e71b90e63c729ffaee0cf845e285c53df296d38db88e14bf1a69582ab/pythonnet/pythonnet/issues/1427 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/1783d69e71b90e63c729ffaee0cf845e285c53df296d38db88e14bf1a69582ab/pythonnet/pythonnet/issues/1427 |
| og:image:alt | Environment Pythonnet version: installed from master branch on 30th March 2021 Python version: 3.9.2 Operating System: Windows 10 .NET Runtime: Microsoft.NETCore.App 5.0.4, Microsoft.WindowsDesktop... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | richard-gemmell-42 |
| 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