Thank you Stéphane,

That worked perfectly!!

 

      From: Stéphane Lozier <stephane.loz...@gmail.com>
 To: Djordje Spasic <issworld2...@yahoo.com> 
Cc: "ironpython-users@python.org" <ironpython-users@python.org>
 Sent: Friday, January 29, 2016 9:02 PM
 Subject: Re: [Ironpython-users] Cannot create instances of that class because 
it is abstract
  
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 <issworld2...@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.​
​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 

// 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.loz...@gmail.com>
 To: Djordje Spasic <issworld2...@yahoo.com> 
Cc: "ironpython-users@python.org" <ironpython-users@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@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. 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:

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@python.org
https://mail.python.org/mailman/listinfo/ironpython-users





   



  
_______________________________________________
Ironpython-users mailing list
Ironpython-users@python.org
https://mail.python.org/mailman/listinfo/ironpython-users

Reply via email to