-
Notifications
You must be signed in to change notification settings - Fork 748
“TypeError: Cannot get managed object” due to getting wrong type info from .NET structs #488
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Firstly,Lets discuss the next snippet: from PyNetFails import A
a = A()
print(type(a.V)) It really produces
You can read more information on official pythonnet documentatition. Take a look at paragraph Type conversion. Secondly,Lets take into account the first notice (result of from System import UInt32
v = UInt32(42)
print(v >= a.V) In the 3-rd line So, this action fails, as pythonnet cannot compare Python objects with CLR and vice versa. from System import UInt32
v = UInt32(42)
print(v >= UInt32(a.V)) or fix problem, by comparing Python objects: v = 42
print(v >= a.V) |
@denfromufa I am convinced it is not a bug. It is a documented behaviour. |
@Konstantin-Posudevskiy yes, that's what I originally suggested to @DfM7. But I'm thinking that this is annoyance and unexpected behavior. |
IMHO, the first step doesn't qualify as a bug, like @Konstantin-Posudevskiy said, it's documented (and sensible) behaviour. Regarding the comparison, I think we could add special cases for the conversion operators that detect mapped Python types and convert them back to their .NET counterpart. |
Seems to be related with #94 |
@Konstantin-Posudevskiy I had read all of the paragraphs in the official documentation before I've posted the question on SO. |
originally reported here: https://stackoverflow.com/questions/44491159 |
As discussed above, this is not a bug. |
Environment
Details
pythonnet fails to get the right type from the struct.
C# code:
Then compile it as class library named
PyNetFails
and run the following Python code:It produces:
<class 'int'>
, although the type should beSystem.UInt32
.Then try to run afterwards the following code:
The text was updated successfully, but these errors were encountered: