[Ironpython-users] Cannot create instances of that class because it is abstract
issworld2000 at yahoo.com
Fri Jan 29 11:55:33 EST 2016
Thank you for the explanation Stéphane.
When I use MapWinGIS.ShapefileClass() instead of MapWinGIS.Shapefile():
sf = MapWinGIS.ShapefileClass()
shpfilename = "C:/example.shp"
sf.Open(shpfilename, None) # raises Error
It raises an error:
Could not convert argument 0 for call to Open.
I googled a couple of times, and found one place where the same issue has emerged: here on stackoverflow.
Stackoverflow issue is actually not related with ironpython, but with ironruby. The author states that the solution is to supply the CLR string as an argument to "Open" function, instead of regular ruby string. I tried that replicating that in ironpython:
shpfilename = clr.Reference[System.String]("c:/example.shp")
But again the upper error message, did not go away.
Further googling found that this kind of issues may happen when trying to call methods in .NET from "Interop COM objects". But only if that method has "ref parameters". Which Open method does not. Here is the signature of the Open method:
Help on method-descriptor Open Open(...)
Open(self: ShapefileClass, ShapefileName: str, cBack: Callback) -> bool
public virtual extern bool Open([MarshalAs(UnmanagedType.BStr)] [In] string ShapefileName, [MarshalAs(UnmanagedType.Interface)] [In] ICallback cBack = null);
I would be very grateful for any kind of advice Stéphane.
From: Stéphane Lozier <stephane.lozier at gmail.com>
To: Djordje Spasic <issworld2000 at yahoo.com>
Cc: "ironpython-users at python.org" <ironpython-users at python.org>
Sent: Friday, January 29, 2016 5:24 PM
Subject: Re: [Ironpython-users] Cannot create instances of that class because it is abstract
Shapefile is an interface with a CoClassAttribute to ShapefileClass (which means when you do new Shapefile() in C# it creates an instance of ShapefileClass). I have no idea what the correct behaviour for IronPython should be, but in this case MapWinGIS.Shapefile gives you the interface.
You could try MapWinGIS.ShapefileClass() instead of MapWinGIS.Shapefile().
On Mon, Jan 25, 2016 at 11:03 AM, Djordje Spasic via Ironpython-users <ironpython-users at python.org> wrote:
I am trying to call a specific method ("Open") from the .NET assembly.The .NET assembly along with all other .dlls and necessary files, can be downloaded from here. It's free an open source project: MapWindow.
In their examples page, by loading the Interop.MapWinGIS.dll file, they call the MapWinGIS.Shapefile.Open() method like so:
string shpfilename = "C:/example.shp";
Shapefile sf = new Shapefile();
if (sf.Open(shpfilename, null))
However, when I try the same thing in ironpython:
shpfilename = "C:/example.shp"
dllsfilename = "C:/mapwindow_dlls"
print "Interop.MapWinGIS.dll loaded: ", "Interop.MapWinGIS" in [assembly.GetName().Name for assembly in clr.References] # prints: True
sf = MapWinGIS.Shapefile() # raises Error
I am getting an error message:
"Message: Cannot create instances of Shapefile because it is abstract"
Why is this happening?
I contacted the author of the project, but couldn't solve the issue.
Any kind of advice would be helpful.
Ironpython-users mailing list
Ironpython-users at python.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Ironpython-users