Title: Python int type is translated to pyInt when passed as a .net Dictionary value only in 3.x version · Issue #1755 · pythonnet/pythonnet · GitHub
Open Graph Title: Python int type is translated to pyInt when passed as a .net Dictionary value only in 3.x version · Issue #1755 · pythonnet/pythonnet
X Title: Python int type is translated to pyInt when passed as a .net Dictionary value only in 3.x version · Issue #1755 · pythonnet/pythonnet
Description: Environment Pythonnet version: 3.0.0a2 Python version: 3.7, 3.8, 3.9, 3.10 Operating System: Windows .NET Runtime: 4.7.2 framework Details After upgrading to pre release 3.0.0a2 version, the python int type is getting translated to PyInt...
Open Graph Description: Environment Pythonnet version: 3.0.0a2 Python version: 3.7, 3.8, 3.9, 3.10 Operating System: Windows .NET Runtime: 4.7.2 framework Details After upgrading to pre release 3.0.0a2 version, the python...
X Description: Environment Pythonnet version: 3.0.0a2 Python version: 3.7, 3.8, 3.9, 3.10 Operating System: Windows .NET Runtime: 4.7.2 framework Details After upgrading to pre release 3.0.0a2 version, the python...
Opengraph URL: https://github.com/pythonnet/pythonnet/issues/1755
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Python int type is translated to pyInt when passed as a .net Dictionary value only in 3.x version","articleBody":"### Environment\r\n\r\n- Pythonnet version: 3.0.0a2\r\n- Python version: 3.7, 3.8, 3.9, 3.10\r\n- Operating System: Windows\r\n- .NET Runtime: 4.7.2 framework\r\n\r\n### Details\r\n\r\nAfter upgrading to pre release 3.0.0a2 version, the python int type is getting translated to PyInt instead of System.int32 inside the .NET DLL, and hence getting a unable to cast exception. this is working fine in 2.x version.\r\n\r\nDLL method: \r\n```csharp\r\npublic void DictMethod(Dictionary\u003cstring, object\u003e paramDict)\r\n {\r\n Console.WriteLine(\"Inside\");\r\n Console.WriteLine(paramDict[\"index\"].GetType().ToString());\r\n var index = Convert.ToInt32((paramDict[\"index\"]));\r\n \r\n }\r\n```\r\nPython script: \r\n\r\n```python\r\n clr.AddReference(\"System.Collections\")\r\nfrom System.Collections.Generic import Dictionary\r\nfrom System import String\r\nfrom System import Object\r\nclr.AddReference(\"PyTest\")\r\nfrom PyTest import PyClass\r\n\r\nclass Utils(object):\r\n\r\n @staticmethod\r\n def prepare_dict(**kwargs):\r\n\r\n dict_net = Dictionary[String,Object]()\r\n for key_value in kwargs.keys():\r\n dict_net.Add(key_value,kwargs[key_value])\r\n return dict_net\r\n\r\nparameters = {}\r\nparameters['index'] = 1\r\nnet_dict = Utils.prepare_dict(**parameters)\r\nobj = PyClass()\r\nobj.DictMethod(net_dict)\r\n```\r\n\r\nOutput in 3.x version:\r\n```\r\nC:\\Users\\Athul\\Desktop\u003ec:\\Python37\\python.exe pynettest.py\r\nInside\r\nPython.Runtime.PyInt\r\nTraceback (most recent call last):\r\n File \"pynettest.py\", line 50, in \u003cmodule\u003e\r\n obj.DictMethod(net_dict)\r\nSystem.InvalidCastException: Unable to cast object of type 'Python.Runtime.PyInt' to type 'System.IConvertible'.\r\n at System.Convert.ToInt32(Object value)\r\n at PyTest.PyClass.DictMethod(Dictionary`2 paramDict) in C:\\Users\\Athul\\source\\repos\\PyTest\\PyClass.cs:line 46\r\n```\r\n\r\n\r\nOutput in 2.x version : \r\n\r\n```\r\nC:\\Users\\Athul\\Desktop\u003ec:\\Python37\\python.exe pynettest.py\r\nInside\r\nSystem.Int32\r\n\r\nC:\\Users\\Athul\\Desktop\u003e\r\n```","author":{"url":"https://github.com/athulds","@type":"Person","name":"athulds"},"datePublished":"2022-04-06T20:59:03.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":3},"url":"https://github.com/1755/pythonnet/issues/1755"}
| 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:01dadeb0-a499-09c7-7045-66427148e497 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 9A6C:E6ADF:18B3271:20A42B8:69719973 |
| html-safe-nonce | 41e03e8dd0f4b905bbf5c87dc43b2ad22bf0250f11531bda1335db83da60ee3b |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5QTZDOkU2QURGOjE4QjMyNzE6MjBBNDJCODo2OTcxOTk3MyIsInZpc2l0b3JfaWQiOiIzOTg5Njk0MTI2MzE0NTkyNjI3IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | ade8db98c14c4c20820887616a7a371691b349d37ecd554cf585a667dc473a4f |
| hovercard-subject-tag | issue:1195180005 |
| 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/1755/issue_layout |
| twitter:image | https://opengraph.githubassets.com/ac0c284cbbaf96bf9c484c89a1f8344bd76b356549a728a6d25b58302f852ea9/pythonnet/pythonnet/issues/1755 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/ac0c284cbbaf96bf9c484c89a1f8344bd76b356549a728a6d25b58302f852ea9/pythonnet/pythonnet/issues/1755 |
| og:image:alt | Environment Pythonnet version: 3.0.0a2 Python version: 3.7, 3.8, 3.9, 3.10 Operating System: Windows .NET Runtime: 4.7.2 framework Details After upgrading to pre release 3.0.0a2 version, the python... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | athulds |
| hostname | github.com |
| expected-hostname | github.com |
| None | fdfdce9cd4f6ab85dca2b0d11264270829297c962dd5a79df449062d7822258f |
| 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 | 51c736e60b302bd039c9d5164573d176ceb24bb2 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width