<div>It&#39;s a feature.&nbsp; clr.AddReferenceToFile ends up calling Assembly.LoadFile under the covers, which lets you load multiple versions of the same assembly.&nbsp; If this isn&#39;t the behavior you want, you should use a differently variant of AddReference (such as clr.AddReference).&nbsp; Each variant has its uses; this one&#39;s don&#39;t correspond well with your intentions.<br>
<br></div>
<div class="gmail_quote">On Sun, Feb 24, 2008 at 2:22 PM, Howland-Rose, Kyle &lt;<a href="mailto:Kyle.Howland-Rose@aar.com.au">Kyle.Howland-Rose@aar.com.au</a>&gt; wrote:<br>
<blockquote class="gmail_quote" style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid">
<div>
<div><font face="Arial" color="#0000ff" size="2"><span>Awesome, thanks Curt.&nbsp; </span></font></div>
<div><font face="Arial" color="#0000ff" size="2"><span></span></font>&nbsp;</div>
<div><font face="Arial" color="#0000ff" size="2"><span>Do you have any idea as to whether this is a bug or a feature?</span></font></div><br>
<div lang="en-us" dir="ltr" align="left">
<hr>
<font face="Tahoma" size="2"><b>From:</b> <a href="mailto:users-bounces@lists.ironpython.com" target="_blank">users-bounces@lists.ironpython.com</a> [mailto:<a href="mailto:users-bounces@lists.ironpython.com" target="_blank">users-bounces@lists.ironpython.com</a>] <b>On Behalf Of </b>Curt Hagenlocher<br>
<b>Sent:</b> Saturday, 23 February 2008 1:33 AM<br><b>To:</b> Discussion of IronPython<br><b>Subject:</b> Re: [IronPython] FW: FW: FW: returning inherited classes to .NET<br></font><br></div>
<div></div>
<div>I built a test executable and was able to reproduce this.&nbsp; And when I changed </div>
<div>clr.AddReferenceToFile(&quot;WebControlLibrary.dll&quot;)</div>
<div>to</div>
<div>clr.AddReference(&quot;WebControlLibrary&quot;)</div>
<div>it worked as expected.<br></div>
<div class="gmail_quote">On Fri, Feb 22, 2008 at 6:02 AM, Curt Hagenlocher &lt;<a href="mailto:curt@hagenlocher.org" target="_blank">curt@hagenlocher.org</a>&gt; wrote:<br>
<blockquote class="gmail_quote" style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid">Ah, no.&nbsp; I was thinking that you would modify your VB code to launch it as a console app (for instance) rather than from inside of <a href="http://asp.net/" target="_blank">ASP.NET</a> -- and see if you still get the same error. 
<div>
<div></div>
<div><br><br>
<div class="gmail_quote">On Thu, Feb 21, 2008 at 10:07 PM, Howland-Rose, Kyle &lt;<a href="mailto:Kyle.Howland-Rose@aar.com.au" target="_blank">Kyle.Howland-Rose@aar.com.au</a>&gt; wrote:<br>
<blockquote class="gmail_quote" style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid">
<div>
<div><font face="Arial" color="#0000ff" size="2"><span>Thanks for your help so late Curt (not that I need a quick answer at all).</span></font></div>
<div><font face="Arial" color="#0000ff" size="2"><span></span></font>&nbsp;</div>
<div><font face="Arial" color="#0000ff" size="2"><span>I am sure I am missing something big-time here and &quot;talking&quot; as cross-purposes, but, to my mind the reason I don&#39;t have a problem when running from the command line is because&nbsp;all I am doing is running the ipy.exe on the file which loads some assemblies, creates a class definition and a function definition&nbsp;and then terminates without even instantiating the class.&nbsp; </span></font><font face="Arial"><font color="#0000ff"><font size="2"><span>Is this what you mean by &quot;running it directly&quot;?&nbsp;</span><span>&nbsp;</span><span>&nbsp;</span></font></font></font></div>

<div><font face="Arial"><font color="#0000ff"><font size="2"><span></span></font></font></font>&nbsp;</div>
<div><font face="Arial"><font color="#0000ff"><font size="2"><span>Thanks again,</span></font></font></font></div>
<div><font face="Arial"><font color="#0000ff"><font size="2"><span>Kyle</span></font></font></font></div>
<div><br></div>
<div lang="en-us" dir="ltr" align="left">
<hr>
<font face="Tahoma" size="2">
<div><b>From:</b> <a href="mailto:users-bounces@lists.ironpython.com" target="_blank">users-bounces@lists.ironpython.com</a> [mailto:<a href="mailto:users-bounces@lists.ironpython.com" target="_blank">users-bounces@lists.ironpython.com</a>] <b>On Behalf Of </b>Curt Hagenlocher<br>
</div><b>Sent:</b> Friday, 22 February 2008 4:55 PM<br><b>To:</b> Discussion of IronPython<br><b>Subject:</b> Re: [IronPython] FW: FW: returning inherited classes to .NET<br></font><br></div>
<div>
<div></div>
<div>
<div></div>
<div>If you&#39;re only getting the error under <a href="http://asp.net/" target="_blank">ASP.NET</a>, then it&#39;s highly likely that you&#39;re loading multiple copies of the same assembly, which is why the CLR can&#39;t cast your Python class back to the VB base -- it literally considers them to be two different classes.&nbsp; This may be related to the way <a href="http://asp.net/" target="_blank">ASP.NET</a> makes shadow copies of your files, but there could be other reasons as well (none of which, unfortunately, come to mind right now).</div>

<div>&nbsp;</div>
<div>Using an interface instead of a base class would give you the same results.<br></div>
<div class="gmail_quote">On Thu, Feb 21, 2008 at 9:44 PM, Howland-Rose, Kyle &lt;<a href="mailto:Kyle.Howland-Rose@aar.com.au" target="_blank">Kyle.Howland-Rose@aar.com.au</a>&gt; wrote:<br>
<blockquote class="gmail_quote" style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid">
<div>
<div><font face="Arial" color="#0000ff" size="2"><span>It runs fine from the command line but then it does not do much ... yet.&nbsp; For the moment I am simplifying it by removing IP :(</span></font></div>
<div><font face="Arial" color="#0000ff" size="2"><span></span></font>&nbsp;</div>
<div><font face="Arial" color="#0000ff" size="2"><span>I wanted to so some moderately heavy reflection which to my thinking should be easier from IP but I will use VB for now.&nbsp; </span></font></div>
<div><font face="Arial" color="#0000ff" size="2"><span></span></font>&nbsp;</div>
<div><font face="Arial" color="#0000ff" size="2"><span>I assume I *should* be able to return a derived python class to VB?&nbsp; Alternatively I could implement an interface.&nbsp; How can IP implement a .NET interface?</span></font></div>

<div><font face="Arial" color="#0000ff" size="2"><span>(All pointers to pre-existing doco warmly received :)</span></font></div>
<div><font face="Arial" color="#0000ff" size="2"><span></span></font>&nbsp;</div>
<div><font face="Arial" color="#0000ff" size="2"><span>Thanks</span></font></div>
<div><font face="Arial" color="#0000ff" size="2"><span>Kyle</span></font></div><br>
<div lang="en-us" dir="ltr" align="left">
<hr>
<font face="Tahoma" size="2">
<div><b>From:</b> <a href="mailto:users-bounces@lists.ironpython.com" target="_blank">users-bounces@lists.ironpython.com</a> [mailto:<a href="mailto:users-bounces@lists.ironpython.com" target="_blank">users-bounces@lists.ironpython.com</a>] <b>On Behalf Of </b>Curt Hagenlocher<br>
</div><b>Sent:</b> Friday, 22 February 2008 4:29 PM<br><b>To:</b> Discussion of IronPython<br><b>Subject:</b> Re: [IronPython] FW: returning inherited classes to .NET<br></font><br></div>
<div>
<div></div>
<div>
<div></div>
<div>My apologies; I wasn&#39;t reading the code correctly.&nbsp; That&#39;s probably a sign that I should be going to bed.&nbsp;:)&nbsp; Have you tried simplifying your version just a little bit by running it directly rather than through <a href="http://asp.net/" target="_blank">ASP.NET</a>?</div>

<div><br>&nbsp;</div>
<div class="gmail_quote">On Thu, Feb 21, 2008 at 8:43 PM, Howland-Rose, Kyle &lt;<a href="mailto:Kyle.Howland-Rose@aar.com.au" target="_blank">Kyle.Howland-Rose@aar.com.au</a>&gt; wrote:<br>
<blockquote class="gmail_quote" style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid">Hi Curt,<br><br>Thanks for replying. &nbsp;When I view the link I see the following:<br><br>The .NET code creates the &quot;Test&quot; class and then runs the python code<br>
which imports the &quot;Test&quot; class a subclasses it to create python class<br>&quot;X&quot;.<br><br>Class &quot;X&quot; is then called and cast to type &quot;Test&quot; and assigned to the<br>value obj.<br><br>Is this what you are looking at?<br>
<br>My code is pretty much identical. &nbsp;The VB looks like:<br><br><br>Public MustInherit Class ChildControl<br>&nbsp; &nbsp;Public Function Control() As WebControl<br>&nbsp; &nbsp; &nbsp; &nbsp;Return Nothing<br>&nbsp; &nbsp;End Function<br>&nbsp; &nbsp;Public Function GetValue() As String<br>
&nbsp; &nbsp; &nbsp; &nbsp;Return Nothing<br>&nbsp; &nbsp;End Function<br>&nbsp; &nbsp;Public Function SetValue(ByVal value As Object) As String<br>&nbsp; &nbsp; &nbsp; &nbsp;Return Nothing<br>&nbsp; &nbsp;End Function<br>End Class<br><br>Class IPReflection<br>&nbsp; &nbsp;Private Shared Instance As IPReflection = Nothing<br>
&nbsp; &nbsp;Private PyEngine As PythonEngine<br>&nbsp; &nbsp;Private PyModule As EngineModule<br><br>&nbsp; &nbsp;Public Shared Function Inst() As IPReflection<br>&nbsp; &nbsp; &nbsp; &nbsp;If Instance Is Nothing Then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Instance = New IPReflection<br>&nbsp; &nbsp; &nbsp; &nbsp;End If<br>
&nbsp; &nbsp; &nbsp; &nbsp;Return Instance<br>&nbsp; &nbsp;End Function<br><br>&nbsp; &nbsp;Private Sub New()<br>&nbsp; &nbsp; &nbsp; &nbsp;Dim path As String = HttpContext.Current.Request.MapPath(&quot;.&quot;)<br>&nbsp; &nbsp; &nbsp; &nbsp;PyEngine = New PythonEngine<br>&nbsp; &nbsp; &nbsp; &nbsp;PyEngine.AddToPath(path)<br>
&nbsp; &nbsp; &nbsp; &nbsp;PyModule = PyEngine.CreateModule<br>&nbsp; &nbsp; &nbsp; &nbsp;PyEngine.DefaultModule = PyModule<br><br>PyEngine.ExecuteFile(HttpContext.Current.Request.MapPath(&quot;CustomControls<br>.py&quot;))<br>&nbsp; &nbsp;End Sub<br><br>&nbsp; &nbsp;Public Function GetChildControl() As ChildControl<br>
&nbsp; &nbsp; &nbsp; &nbsp;Return<br>CType(Operations.Ops.Call(PyModule.Globals(&quot;GetControl&quot;)), ChildControl)<br>&nbsp; &nbsp;End Function<br>End Class<br><br>And the python looks like:<br><br>import clr<br>import sys<br><br>clr.AddReference(&#39;System&#39;)<br>
import System<br><br>sys.path.append(sys.path[0] + &quot;/bin&quot;)<br><br>clr.AddReferenceToFile(&quot;WebControlLibrary.dll&quot;)<br>clr.AddReference(&#39;System.Web&#39;)<br><br>from System.Web.UI.WebControls import Label<br>
<br>from WebControlLibrary import ChildControl<br><br>class LabelChildControl(ChildControl):<br>&nbsp; &nbsp; &nbsp; &nbsp;def __init__(self):<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;self.control = Label()<br>&nbsp; &nbsp; &nbsp; &nbsp;def Control(self):<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return self.control<br>
<br>def GetControl():<br>&nbsp; &nbsp; &nbsp; &nbsp;return LabelChildControl()<br><br><br>Thanks again,<br>Kyle<br>
<div><br>________________________________<br><br>From: <a href="mailto:users-bounces@lists.ironpython.com" target="_blank">users-bounces@lists.ironpython.com</a><br></div>[mailto:<a href="mailto:users-bounces@lists.ironpython.com" target="_blank">users-bounces@lists.ironpython.com</a>] On Behalf Of Curt<br>
Hagenlocher<br>Sent: Friday, 22 February 2008 3:08 PM<br>To: Discussion of IronPython<br>Subject: Re: [IronPython] returning inherited classes to .NET<br>
<div>
<div></div>
<div><br><br>The page in question doesn&#39;t seem to show what you describe -- deriving<br>a Python class from a C# class. &nbsp;Maybe you could show us your sample<br>code?<br><br><br>On Thu, Feb 21, 2008 at 7:39 PM, Howland-Rose, Kyle<br>
&lt;<a href="mailto:Kyle.Howland-Rose@aar.com.au" target="_blank">Kyle.Howland-Rose@aar.com.au</a>&gt; wrote:<br><br><br>&nbsp; &nbsp; &nbsp; &nbsp;Hi all,<br>&nbsp; &nbsp; &nbsp; &nbsp;I am following<br><br><br><a href="http://www.ironpython.info/index.php/Using_Python_Classes_from_.NET" target="_blank">http://www.ironpython.info/index.php/Using_Python_Classes_from_.NET</a><br>
&lt;<a href="http://www.ironpython.info/index.php/Using_Python_Classes_from_.NET" target="_blank">http://www.ironpython.info/index.php/Using_Python_Classes_from_.NET</a>&gt;<br>but using VB.<br><br>&nbsp; &nbsp; &nbsp; &nbsp;In VB I declare a class and derive a python 1.1 class from it<br>
but when I return it I get the exception:<br><br>&nbsp; &nbsp; &nbsp; &nbsp;&quot;Unable to cast object of type<br>&#39;IronPython.NewTypes.WebControlLibrary.ChildControl_1&#39; to type<br>&#39;WebControlLibrary.ChildControl&#39;.&quot;<br><br>
&nbsp; &nbsp; &nbsp; &nbsp;The page referenced above just seems to cast the python class<br>instance to the C# class instance but this does not work for me in VB.<br><br>&nbsp; &nbsp; &nbsp; &nbsp;Any help would be appreciated :)<br><br>&nbsp; &nbsp; &nbsp; &nbsp;Thanks,<br><br>&nbsp; &nbsp; &nbsp; &nbsp;Kyle<br>
<br><br><br><br>************************************************************************<br><br>&nbsp; &nbsp; &nbsp; &nbsp;Allens Arthur Robinson online: <a href="http://www.aar.com.au/" target="_blank">http://www.aar.com.au</a><br>&lt;<a href="http://www.aar.com.au/" target="_blank">http://www.aar.com.au/</a>&gt;<br>
<br>&nbsp; &nbsp; &nbsp; &nbsp;This email is confidential and may be subject to legal or other<br>professional privilege. It is also subject to copyright. If you have<br>received it in error, confidentiality and privilege are not waived and<br>
you must not disclose or use the information in it. Please notify the<br>sender by return email and delete it from your system. Any personal<br>information in this email must be handled in accordance with the Privacy<br>Act 1988 (Cth).<br>
<br><br>************************************************************************<br>*<br><br><br><br><br>************************************************************************<br><br>&nbsp; &nbsp; &nbsp; &nbsp;Allens Arthur Robinson online: <a href="http://www.aar.com.au/" target="_blank">http://www.aar.com.au</a><br>
&lt;<a href="http://www.aar.com.au/" target="_blank">http://www.aar.com.au/</a>&gt;<br><br>&nbsp; &nbsp; &nbsp; &nbsp;This email is confidential and may be subject to legal or other<br>professional privilege. It is also subject to copyright. If you have<br>
received it in error, confidentiality and privilege are not waived and<br>you must not disclose or use the information in it. Please notify the<br>sender by return email and delete it from your system. Any personal<br>information in this email must be handled in accordance with the Privacy<br>
Act 1988 (Cth).<br><br><br>************************************************************************<br>*<br><br><br>&nbsp; &nbsp; &nbsp; &nbsp;_______________________________________________<br>&nbsp; &nbsp; &nbsp; &nbsp;Users mailing list<br>&nbsp; &nbsp; &nbsp; &nbsp;<a href="mailto:Users@lists.ironpython.com" target="_blank">Users@lists.ironpython.com</a><br>
&nbsp; &nbsp; &nbsp; &nbsp;<a href="http://lists.ironpython.com/listinfo.cgi/users-ironpython.com" target="_blank">http://lists.ironpython.com/listinfo.cgi/users-ironpython.com</a><br><br>&nbsp; &nbsp; &nbsp; &nbsp;_______________________________________________<br>
&nbsp; &nbsp; &nbsp; &nbsp;Users mailing list<br>&nbsp; &nbsp; &nbsp; &nbsp;<a href="mailto:Users@lists.ironpython.com" target="_blank">Users@lists.ironpython.com</a><br>&nbsp; &nbsp; &nbsp; &nbsp;<a href="http://lists.ironpython.com/listinfo.cgi/users-ironpython.com" target="_blank">http://lists.ironpython.com/listinfo.cgi/users-ironpython.com</a><br>
<br><br><br><br><br>************************************************************************<br><br>Allens Arthur Robinson online: <a href="http://www.aar.com.au/" target="_blank">http://www.aar.com.au</a><br><br>This email is confidential and may be subject to legal or other professional privilege. It is also subject to copyright. If you have received it in error, confidentiality and privilege are not waived and you must not disclose or use the information in it. Please notify the sender by return email and delete it from your system. Any personal information in this email must be handled in accordance with the Privacy Act 1988 (Cth).<br>
<br>*************************************************************************<br></div></div><br>_______________________________________________<br>Users mailing list<br><a href="mailto:Users@lists.ironpython.com" target="_blank">Users@lists.ironpython.com</a><br>
<a href="http://lists.ironpython.com/listinfo.cgi/users-ironpython.com" target="_blank">http://lists.ironpython.com/listinfo.cgi/users-ironpython.com</a><br><br>_______________________________________________<br>Users mailing list<br>
<a href="mailto:Users@lists.ironpython.com" target="_blank">Users@lists.ironpython.com</a><br><a href="http://lists.ironpython.com/listinfo.cgi/users-ironpython.com" target="_blank">http://lists.ironpython.com/listinfo.cgi/users-ironpython.com</a><br>
<br></blockquote></div><br>
<p>&nbsp;</p>
<p>************************************************************************<br>&nbsp;<br>Allens Arthur Robinson online: <a href="http://www.aar.com.au/" target="_blank">http://www.aar.com.au</a><br>&nbsp;<br>This email is confidential and may be subject to legal or other professional privilege. It is also subject to copyright. If you have received it in error, confidentiality and privilege are not waived and you must not disclose or use the information in it. Please notify the sender by return email and delete it from your system. Any personal information in this email must be handled in accordance with the Privacy Act 1988 (Cth).<br>
&nbsp;<br>*************************************************************************</p></div></div></div><br>_______________________________________________<br>Users mailing list<br><a href="mailto:Users@lists.ironpython.com" target="_blank">Users@lists.ironpython.com</a><br>
<a href="http://lists.ironpython.com/listinfo.cgi/users-ironpython.com" target="_blank">http://lists.ironpython.com/listinfo.cgi/users-ironpython.com</a><br><br>_______________________________________________<br>Users mailing list<br>
<a href="mailto:Users@lists.ironpython.com" target="_blank">Users@lists.ironpython.com</a><br><a href="http://lists.ironpython.com/listinfo.cgi/users-ironpython.com" target="_blank">http://lists.ironpython.com/listinfo.cgi/users-ironpython.com</a><br>
<br></blockquote></div><br>
<p>&nbsp;</p>
<p>************************************************************************<br>&nbsp;<br>Allens Arthur Robinson online: <a href="http://www.aar.com.au/" target="_blank">http://www.aar.com.au</a><br>&nbsp;<br>This email is confidential and may be subject to legal or other professional privilege. It is also subject to copyright. If you have received it in error, confidentiality and privilege are not waived and you must not disclose or use the information in it. Please notify the sender by return email and delete it from your system. Any personal information in this email must be handled in accordance with the Privacy Act 1988 (Cth).<br>
&nbsp;<br>*************************************************************************</p></div></div></div><br>_______________________________________________<br>Users mailing list<br><a href="mailto:Users@lists.ironpython.com" target="_blank">Users@lists.ironpython.com</a><br>
<a href="http://lists.ironpython.com/listinfo.cgi/users-ironpython.com" target="_blank">http://lists.ironpython.com/listinfo.cgi/users-ironpython.com</a><br><br>_______________________________________________<br>Users mailing list<br>
<a href="mailto:Users@lists.ironpython.com" target="_blank">Users@lists.ironpython.com</a><br><a href="http://lists.ironpython.com/listinfo.cgi/users-ironpython.com" target="_blank">http://lists.ironpython.com/listinfo.cgi/users-ironpython.com</a><br>
<br></blockquote></div><br></div></div></blockquote></div><br>
<p>&nbsp;</p>
<p>************************************************************************<br>&nbsp;<br>Allens Arthur Robinson online: <a href="http://www.aar.com.au/" target="_blank">http://www.aar.com.au</a><br>&nbsp;<br>This email is confidential and may be subject to legal or other professional privilege. It is also subject to copyright. If you have received it in error, confidentiality and privilege are not waived and you must not disclose or use the information in it. Please notify the sender by return email and delete it from your system. Any personal information in this email must be handled in accordance with the Privacy Act 1988 (Cth).<br>
&nbsp;<br>*************************************************************************</p></div><br>_______________________________________________<br>Users mailing list<br><a href="mailto:Users@lists.ironpython.com">Users@lists.ironpython.com</a><br>
<a href="http://lists.ironpython.com/listinfo.cgi/users-ironpython.com" target="_blank">http://lists.ironpython.com/listinfo.cgi/users-ironpython.com</a><br><br>_______________________________________________<br>Users mailing list<br>
<a href="mailto:Users@lists.ironpython.com">Users@lists.ironpython.com</a><br><a href="http://lists.ironpython.com/listinfo.cgi/users-ironpython.com" target="_blank">http://lists.ironpython.com/listinfo.cgi/users-ironpython.com</a><br>
<br></blockquote></div><br>