[Ironpython-users] Cannot create instances of that class because it is abstract

Stéphane Lozier stephane.lozier at gmail.com
Fri Jan 29 15:02:11 EST 2016


I can't say I really know what's going on, but you could try using unbound
class instance methods (see
http://ironpython.net/documentation/dotnet/dotnet.html#using-unbound-class-instance-methods
).

For example:
MapWinGIS.Shapefile.Open(sf, shpfilename, None)

On Fri, Jan 29, 2016 at 11:55 AM, Djordje Spasic <issworld2000 at yahoo.com>
wrote:

> Thank you for the explanation Stéphane.
>
> When I use MapWinGIS.ShapefileClass() instead of MapWinGIS.Shapefile():
>
>     import clr
>
>
> clr.AddReferenceToFileAndPath("C:/mapwindow_dlls/Interop.MapWinGIS.dll")
>
>     import MapWinGIS
>
>     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
> <http://stackoverflow.com/questions/2296714/ironruby-cannot-call-method-on-a-com-object-with-one-or-more-arguments>
> .​
> ​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*"
> <http://stackoverflow.com/questions/8529313/how-do-i-call-a-vb6-com-object-from-c-sharp-with-dynamic-when-it-has-a-ref-param>.
> 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
>
> // MapWinGIS.ShapefileClass
> [DispId(11)]
> [MethodImpl(MethodImplOptions.InternalCall)]
> 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.
>
> Kind regards,
> Djordje Spasic
>
>
> ------------------------------
> *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:
>
> Hello,
>
> 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
> <https://mapwindow4.codeplex.com/releases/view/110244>. It's free an open
> source project: MapWindow.
>
> In their examples page
> <http://www.mapwindow.org/documentation/mapwingis4.9/examples.html>, by
> loading the *Interop.MapWinGIS.dll* file, they call the *MapWinGIS.*
> *Shapefile.Open()* method like so:
>
> using MapWinGIS;
>
> string shpfilename = "C:/example.shp";
> Shapefile sf = new Shapefile();
> if (sf.*Open*(shpfilename, null))
> {
> }
>
>
> However, when I try the same thing in ironpython:
>
>     import clr
>     import os
>
>     shpfilename = "C:/example.shp"
>     dllsfilename = "C:/mapwindow_dlls"
>
>     clr.AddReferenceToFileAndPath(os.path.join(dllsfilename,
> "Interop.MapWinGIS.dll"))
>     print "Interop.MapWinGIS.dll loaded: ", "Interop.MapWinGIS" in
> [assembly.GetName().Name for assembly in clr.References]  # prints: True
>     import MapWinGIS
>
>     sf = MapWinGIS.Shapefile()  # raises Error
>     sf.*Open*(shpfilename, None)
>
>
> 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.
>
> Kind regards,
> Djordje Spasic
>
>
> _______________________________________________
> Ironpython-users mailing list
> Ironpython-users at python.org
> https://mail.python.org/mailman/listinfo/ironpython-users
>
>
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ironpython-users/attachments/20160129/5866da21/attachment.html>


More information about the Ironpython-users mailing list