You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe what you were trying to get done:
Adding items to a C# generic list inside C# class using Python fails. List is a class instance variable which is exposed outside the class using getter/setter. In pythonnet 2.3 & IronPython list inside class is exposed as C# list to Python code. However starting with pythonnet 2.4 it is exposed as python list. Adding items to that list works fine on pythonnet 2.3 & IronPython but not with pythonnet 2.4.
What commands did you run to trigger this issue?
Minimal example C# class. Save as example_dll_limited.cs:
namespace example_dll_limited {
using System;
using System.Collections;
using System.Collections.Generic;
public class CollectionClass {
private List<string> sequenceItemField;
public CollectionClass() {
this.sequenceItemField = new List<string>();
}
public int SizeCheck() {
return this.sequenceItemField.Count;
}
public List<string> SequenceItem {
get {
return this.sequenceItemField;
}
set {
this.sequenceItemField = value;
}
}
}
}
Generate library dll from example class using csc:
csc.exe /t:library example_dll_limited.cs
# Or with full path to csc if not in path:
C:\Windows\Microsoft.NET\Framework\v4.0.30319\csc.exe /t:library example_dll_limited.cs
Execute following python commands which instantiate single instance of class and tries to add two elements to the list inside the class:
from __future__ importprint_functionimportclrclr.AddReference('example_dll_limited')
importexample_dll_limited# Create objectobject_=example_dll_limited.CollectionClass()
# prints Python list on 2.4, C# List on python 2.3print(type(object_.SequenceItem))
ifnothasattr(clr, '__version__') orclr.__version__.startswith('2.3'):
# This one works correctly with IronPython & pythonnet 2.3object_.SequenceItem.Add('first_item')
object_.SequenceItem.Add('second_item')
size=object_.SequenceItem.Countelse:
# Pythonnet 2.4 seems to do implicit list conversion# This one doesn't add anything to python list with pythonnet 2.4devretval=object_.SequenceItem.append('first_item')
object_.SequenceItem.append('second_item')
size=len(object_.SequenceItem)
size_explicit=object_.SizeCheck()
print('List should have 2 items')
print('Size check: {}'.format(size))
print('Explicit method call size check: {}'.format(size_explicit))
Output using pythonnet 2.3:
<class 'System.Collections.Generic.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]'>
List should have 2 items
Size check: 2
Explicit method call size check: 2
Output using pythonnet 2.4dev
<type 'list'>
List should have 2 items
Size check: 0
Explicit method call size check: 0
If there was a crash, please include the traceback here.
No crash
The text was updated successfully, but these errors were encountered:
Environment
Details
Describe what you were trying to get done:
Adding items to a C# generic list inside C# class using Python fails. List is a class instance variable which is exposed outside the class using getter/setter. In pythonnet 2.3 & IronPython list inside class is exposed as C# list to Python code. However starting with pythonnet 2.4 it is exposed as python list. Adding items to that list works fine on pythonnet 2.3 & IronPython but not with pythonnet 2.4.
What commands did you run to trigger this issue?
Minimal example C# class. Save as example_dll_limited.cs:
Generate library dll from example class using csc:
Execute following python commands which instantiate single instance of class and tries to add two elements to the list inside the class:
Output using pythonnet 2.3:
Output using pythonnet 2.4dev
No crash
The text was updated successfully, but these errors were encountered: