<html><head></head><body><div style="color:#000; background-color:#fff; font-family:verdana, helvetica, sans-serif;font-size:13px"><div id="yiv2363887580"><div id="yui_3_16_0_1_1455401171494_4742"><div id="yui_3_16_0_1_1455401171494_4741" style="color:#000;background-color:#fff;font-family:verdana, helvetica, sans-serif;font-size:13px;"><div dir="ltr" id="yiv2363887580yui_3_16_0_1_1454060246609_75022"><span id="yiv2363887580yui_3_16_0_1_1454060246609_75030">Thank you Stéphane,<br clear="none"><br clear="none">That worked perfectly!!<br clear="none"></span></div><div dir="ltr" id="yiv2363887580yui_3_16_0_1_1454060246609_75031"><span id="yiv2363887580yui_3_16_0_1_1454060246609_75030"></span></div><br clear="none"> <div class="yiv2363887580qtdSeparateBR" id="yiv2363887580yui_3_16_0_1_1454060246609_75021"><br clear="none"><br clear="none"></div><div class="yiv2363887580yqt0404338416" id="yiv2363887580yqt00551"></div></div></div></div><div class=".yiv2363887580yahoo_quoted"> <div id="yiv2363887580yui_3_16_0_1_1454060246609_74973" style="font-family:verdana, helvetica, sans-serif;font-size:13px;"> <div id="yiv2363887580yui_3_16_0_1_1454060246609_74972" style="font-family:HelveticaNeue, Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif;font-size:16px;"> <div dir="ltr" id="yiv2363887580yui_3_16_0_1_1454060246609_74971"> <font id="yiv2363887580yui_3_16_0_1_1454060246609_74970" face="Arial" size="2"> </font><hr id="yiv2363887580yui_3_16_0_1_1454060246609_75203" size="1"> <b><span style="font-weight:bold;">From:</span></b> Stéphane Lozier <stephane.lozier@gmail.com><br clear="none"> <b><span style="font-weight:bold;">To:</span></b> Djordje Spasic <issworld2000@yahoo.com> <br clear="none"><b><span style="font-weight:bold;">Cc:</span></b> "ironpython-users@python.org" <ironpython-users@python.org><br clear="none"> <b id="yiv2363887580yui_3_16_0_1_1454060246609_75020"><span id="yiv2363887580yui_3_16_0_1_1454060246609_75019" style="font-weight:bold;">Sent:</span></b> Friday, January 29, 2016 9:02 PM<br clear="none"> <b><span style="font-weight:bold;">Subject:</span></b> Re: [Ironpython-users] Cannot create instances of that class because it is abstract<br clear="none"> </div> <div class="yiv2363887580y_msg_container" id="yiv2363887580yui_3_16_0_1_1454060246609_74975"><br clear="none"><div id="yiv2363887580"><div id="yiv2363887580yui_3_16_0_1_1454060246609_74978"><div dir="ltr" id="yiv2363887580yui_3_16_0_1_1454060246609_74977"><div id="yiv2363887580yui_3_16_0_1_1454060246609_74976">I can't say I really know what's going on, but you could try using unbound class instance methods (see <a rel="nofollow" shape="rect" id="yiv2363887580yui_3_16_0_1_1454060246609_74979" target="_blank" href="http://ironpython.net/documentation/dotnet/dotnet.html#using-unbound-class-instance-methods">http://ironpython.net/documentation/dotnet/dotnet.html#using-unbound-class-instance-methods</a>).<br clear="none"></div><div id="yiv2363887580yui_3_16_0_1_1454060246609_74986"><br clear="none">For example:<br clear="none"></div>MapWinGIS.Shapefile.Open(sf, shpfilename, None)<br clear="none"></div><div class="yiv2363887580yqt8242858582" id="yiv2363887580yqt82064"><div class="yiv2363887580gmail_extra" id="yiv2363887580yui_3_16_0_1_1454060246609_74996"><br clear="none"><div class="yiv2363887580gmail_quote" id="yiv2363887580yui_3_16_0_1_1454060246609_74995">On Fri, Jan 29, 2016 at 11:55 AM, Djordje Spasic <span dir="ltr" id="yiv2363887580yui_3_16_0_1_1454060246609_75150"><<a rel="nofollow" shape="rect" id="yiv2363887580yui_3_16_0_1_1454060246609_75235" ymailto="mailto:issworld2000@yahoo.com" target="_blank" href="mailto:issworld2000@yahoo.com">issworld2000@yahoo.com</a>></span> wrote:<br clear="none"><blockquote class="yiv2363887580gmail_quote" id="yiv2363887580yui_3_16_0_1_1454060246609_74994" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><div id="yiv2363887580yui_3_16_0_1_1454060246609_74993"><div id="yiv2363887580yui_3_16_0_1_1454060246609_74992" style="color:#000;background-color:#fff;font-family:verdana, helvetica, sans-serif;font-size:13px;"><div id="yiv2363887580yui_3_16_0_1_1454060246609_74991"><div id="yiv2363887580yui_3_16_0_1_1454060246609_74990"><div id="yiv2363887580yui_3_16_0_1_1454060246609_74989" style="color:#000;background-color:#fff;font-family:verdana, helvetica, sans-serif;font-size:13px;"><div><span></span></div><div id="yiv2363887580yui_3_16_0_1_1454060246609_74988"><div id="yiv2363887580yui_3_16_0_1_1454060246609_74987">Thank you for the explanation Stéphane.</div><div id="yiv2363887580yui_3_16_0_1_1454060246609_75151"><br clear="none"></div></div><div dir="ltr">When I use MapWinGIS.ShapefileClass() instead of MapWinGIS.Shapefile():</div><div dir="ltr"><br clear="none"></div><div dir="ltr"> import clr<br clear="none"> <br clear="none"> clr.AddReferenceToFileAndPath("C:/mapwindow_dlls/Interop.MapWinGIS.dll")<br clear="none"><br clear="none"> import MapWinGIS<br clear="none"> <br clear="none"> sf = MapWinGIS.<b>ShapefileClass</b>()<br clear="none"> shpfilename = "C:/example.shp"<br clear="none"> sf.Open(shpfilename, None) # raises Error<br clear="none"></div><div dir="ltr"><br clear="none"></div><div><div>It raises an error:</div><div><blockquote><div dir="ltr"><i>Could not convert argument 0 for call to Open.</i></div></blockquote><div dir="ltr"><span><span>I googled a couple of times, and found one place where the same issue has emerged: <a rel="nofollow" shape="rect" target="_blank" href="http://stackoverflow.com/questions/2296714/ironruby-cannot-call-method-on-a-com-object-with-one-or-more-arguments">here on stackoverflow</a>.<br clear="none">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:<br clear="none"></span></span></div><blockquote><div dir="ltr"><span><span></span></span><span><span>shpfilename = clr.Reference[System.String]("c:/example.shp")</span></span></div></blockquote><div dir="ltr"><span><span>But again the upper error message, did not go away.</span></span><span></span></div><div dir="ltr"><br clear="none"></div><div dir="ltr">Further googling found that this kind of issues may happen when trying <a rel="nofollow" shape="rect" target="_blank" href="http://stackoverflow.com/questions/8529313/how-do-i-call-a-vb6-com-object-from-c-sharp-with-dynamic-when-it-has-a-ref-param">to call methods in .NET from "<i>Interop COM objects</i>"</a>. But only if that method has "<i>ref parameters</i>". Which <i>Open</i> method does not. Here is the signature of the <i>Open</i> method:</div><div dir="ltr"><br clear="none"></div><blockquote><div dir="ltr">Help on method-descriptor Open Open(...)<br clear="none"> Open(self: ShapefileClass, ShapefileName: str, cBack: Callback) -> bool <br clear="none"><br clear="none">// MapWinGIS.ShapefileClass<br clear="none">[DispId(11)]<br clear="none">[MethodImpl(MethodImplOptions.InternalCall)]<br clear="none">public virtual extern bool Open([MarshalAs(UnmanagedType.BStr)] [In] string ShapefileName, [MarshalAs(UnmanagedType.Interface)] [In] ICallback cBack = null);</div></blockquote><div dir="ltr"><br clear="none">I would be very grateful for any kind of advice Stéphane.<br clear="none"><br clear="none">Kind regards,<br clear="none"></div><div dir="ltr">Djordje Spasic<br clear="none"></div><div dir="ltr"><i><br clear="none"></i></div></div><br clear="none"></div><div></div></div></div></div><div> <div style="font-family:verdana, helvetica, sans-serif;font-size:13px;"> <div style="font-family:HelveticaNeue, Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif;font-size:16px;"> <div dir="ltr"> <font face="Arial" size="2"> </font><hr size="1"> <b><span style="font-weight:bold;">From:</span></b> Stéphane Lozier <<a rel="nofollow" shape="rect" ymailto="mailto:stephane.lozier@gmail.com" target="_blank" href="mailto:stephane.lozier@gmail.com">stephane.lozier@gmail.com</a>><br clear="none"> <b><span style="font-weight:bold;">To:</span></b> Djordje Spasic <<a rel="nofollow" shape="rect" ymailto="mailto:issworld2000@yahoo.com" target="_blank" href="mailto:issworld2000@yahoo.com">issworld2000@yahoo.com</a>> <br clear="none"><b><span style="font-weight:bold;">Cc:</span></b> "<a rel="nofollow" shape="rect" ymailto="mailto:ironpython-users@python.org" target="_blank" href="mailto:ironpython-users@python.org">ironpython-users@python.org</a>" <<a rel="nofollow" shape="rect" ymailto="mailto:ironpython-users@python.org" target="_blank" href="mailto:ironpython-users@python.org">ironpython-users@python.org</a>><br clear="none"> <b><span style="font-weight:bold;">Sent:</span></b> Friday, January 29, 2016 5:24 PM<br clear="none"> <b><span style="font-weight:bold;">Subject:</span></b> Re: [Ironpython-users] Cannot create instances of that class because it is abstract<br clear="none"> </div> <div><br clear="none"><div><div><div dir="ltr"><div>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.<br clear="none"><br clear="none"></div>You could try MapWinGIS.ShapefileClass() instead of MapWinGIS.Shapefile().<br clear="none"><br clear="none"><br clear="none"></div><div><br clear="none"><div>On Mon, Jan 25, 2016 at 11:03 AM, Djordje Spasic via Ironpython-users <span dir="ltr"><<a rel="nofollow" shape="rect" ymailto="mailto:ironpython-users@python.org" target="_blank" href="mailto:ironpython-users@python.org">ironpython-users@python.org</a>></span> wrote:<br clear="none"><blockquote style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><div><div><div style="color:#000;background-color:#fff;font-family:verdana, helvetica, sans-serif;font-size:13px;"><div>Hello,<br clear="none"><br clear="none">I am trying to call a specific method ("Open") from the .NET assembly.</div><div dir="ltr">The .NET assembly along with all other .dlls and necessary files, can be downloaded <a rel="nofollow" shape="rect" target="_blank" href="https://mapwindow4.codeplex.com/releases/view/110244">from here</a>. It's free an open source project: MapWindow.</div><div dir="ltr"><br clear="none"></div><div dir="ltr">In their <a rel="nofollow" shape="rect" target="_blank" href="http://www.mapwindow.org/documentation/mapwingis4.9/examples.html">examples page</a>, by loading the <i>Interop.MapWinGIS.dll</i> file, they call the <i>MapWinGIS.</i><span><i>Shapefile.Open()</i> method like so:</span></div><div dir="ltr"><br clear="none"></div><blockquote><div dir="ltr"><span><span>using MapWinGIS;</span></span></div><div dir="ltr"><br clear="none"><span><span></span></span></div><div dir="ltr"><span><span>string </span></span><span><span>shpfilename = "</span></span><span><span>C:/example.shp";<br clear="none"></span></span></div><div dir="ltr"><span><span>Shapefile sf = new Shapefile();<br clear="none">if (sf.<b>Open</b>(</span></span><span><span>shpfilename, null))<br clear="none">{<br clear="none">}</span></span><span></span><b><br clear="none"></b></div></blockquote><div><br clear="none"></div><div>However, when I try the same thing in ironpython:</div><div><br clear="none"></div><div dir="ltr"> import clr<br clear="none"> import os<br clear="none"> <br clear="none"> shpfilename = "C:/example.shp"<br clear="none"> dllsfilename = "C:/mapwindow_dlls"<br clear="none"> <br clear="none"> clr.AddReferenceToFileAndPath(os.path.join(dllsfilename, "Interop.MapWinGIS.dll"))<br clear="none"> print "Interop.MapWinGIS.dll loaded: ", "Interop.MapWinGIS" in [assembly.GetName().Name for assembly in clr.References] # prints: True<br clear="none"> import MapWinGIS<br clear="none"> <br clear="none"> sf = MapWinGIS.Shapefile() # raises Error<br clear="none"> sf.<b>Open</b>(shpfilename, None)<br clear="none"></div><div><br clear="none"></div><div><br clear="none"></div><div dir="ltr">I am getting an error message:</div><div dir="ltr"><br clear="none"></div><div dir="ltr"><i> "Message: Cannot create instances of Shapefile because it is abstract"</i></div><div dir="ltr"><span></span><span><br clear="none">Why is this happening?</span></div><div dir="ltr"><br clear="none"><span></span></div><div dir="ltr">I contacted the author of the project, but couldn't solve the issue.</div><div dir="ltr"><br clear="none"></div><div dir="ltr">Any kind of advice would be helpful.</div><div dir="ltr"><br clear="none"></div><div dir="ltr">Kind regards,<br clear="none">Djordje Spasic<br clear="none"><span></span></div><div dir="ltr"><span></span><br clear="none"></div></div></div></div><br clear="none">_______________________________________________<br clear="none">
Ironpython-users mailing list<br clear="none">
<a rel="nofollow" shape="rect" ymailto="mailto:Ironpython-users@python.org" target="_blank" href="mailto:Ironpython-users@python.org">Ironpython-users@python.org</a><br clear="none">
<a rel="nofollow" shape="rect" target="_blank" href="https://mail.python.org/mailman/listinfo/ironpython-users">https://mail.python.org/mailman/listinfo/ironpython-users</a><br clear="none">
<br clear="none"></blockquote></div><br clear="none"></div></div></div><br clear="none"><br clear="none"></div> </div> </div> </div></div></div></blockquote></div><br clear="none"></div></div></div></div><br clear="none"><br clear="none"></div> </div> </div> </div></div></body></html>