<div dir="ltr">Thank you for the replies.<div><br></div><div>Now, I recompiled Python.Net with .Net 4.0 and get below working with simple AAA.BBB.Adapter after reading</div><div><br></div><div><a href="http://stackoverflow.com/questions/14520888/clr-addreferenceexample-file-unable-to-find-assembly?rq=1">http://stackoverflow.com/questions/14520888/clr-addreferenceexample-file-unable-to-find-assembly?rq=1</a></div>
<div><div><a href="http://stackoverflow.com/questions/13259617/python-for-net-unable-to-find-assembly-error?rq=1">http://stackoverflow.com/questions/13259617/python-for-net-unable-to-find-assembly-error?rq=1</a><br></div>
<div><a href="http://sourceforge.net/p/pythonnet/bugs/17/">http://sourceforge.net/p/pythonnet/bugs/17/</a><br></div><div><a href="http://sourceforge.net/p/pythonnet/bugs/18/">http://sourceforge.net/p/pythonnet/bugs/18/</a><br>
</div><div><br></div><div><br></div><div><div style>Now I have below sample code(Adapter.proj has two c# files), and experimented</div><div><br></div><div><div>Class1.cs</div><div>-----------</div><div><div>namespace AAA.BBB.CCC</div>
<div>{</div><div><br></div><div> public class Adapter</div><div> {</div><div> public string Function1()</div><div> {</div><div> return "AAA.BBB.CCC: Adapter Function1 Called";</div>
<div> }</div><div> public void Function2()</div><div> {</div><div> Console.WriteLine("AAA.BBB.CCC: Adapter Function2");</div><div> }</div><div> }</div><div><br></div><div>
public class Network</div><div> {</div><div> public string Function1()</div><div> {</div><div> return "AAA.BBB.CCC: Network Function1 called";</div><div> }</div><div><br></div>
<div> public void Function2()</div><div> {</div><div> Console.WriteLine("AAA.BBB.CCC: Network Function2");</div><div> }</div><div> }</div><div>}</div><div><br></div><div>namespace AAA.BBB</div>
<div>{</div><div> public class Adapter</div><div> {</div><div> public string Function1()</div><div> {</div><div> return "AAA.BBB: Adapter Function1 Called";</div><div> }</div>
<div> public void Function2()</div><div> {</div><div> Console.WriteLine("AAA.BBB: Adapter Function2");</div><div> }</div><div> }</div><div><br></div><div> public class Network</div>
<div> {</div><div> public string Function1()</div><div> {</div><div> return "AAA.BBB: Network Function1 called";</div><div> }</div><div><br></div><div> public void Function2()</div>
<div> {</div><div> Console.WriteLine("AAA.BBB: Network Function2");</div><div> }</div><div> }</div><div><br></div><div>}</div><div><br></div></div><div>Class2.cs</div><div>-----------</div>
<div><div>namespace AAA.CCC</div><div>{</div><div> public class Adapter</div><div> {</div><div> public string Function1()</div><div> {</div><div> return "AAA.CCC: Adapter Function1 Called";</div>
<div> }</div><div> public void Function2()</div><div> {</div><div> Console.WriteLine("AAA.CCC: Adapter Function2");</div><div> }</div><div> }</div><div>}</div></div><div>
<br></div><div>Then, I got below. It seems working great.</div><div><br></div><div><div>C:\Automation\PythonNet>nPython.exe</div><div>Python 2.7.3 (default, Apr 10 2012, 23:31:26) [MSC v.1500 32 bit (Intel)] on win32</div>
<div>Type "help", "copyright", "credits" or "license" for more information.</div><div>>>> import sys</div><div>>>> sys.path.append("c:\\automation\\pythonnet")</div>
<div>>>> import clr</div><div>>>> clr.FindAssembly("Adapter")</div><div>u'Adapter.dll'</div><div>>>> clr.AddReference("Adapter")</div><div><System.Reflection.RuntimeAssembly object at 0x052E5828></div>
<div>>>> adapter1 = Adapter()</div><div>Traceback (most recent call last):</div><div> File "<stdin>", line 1, in <module></div><div>NameError: name 'Adapter' is not defined</div><div>
>>> from AAA.BBB.CCC import Adapter</div><div>>>> from AAA.BBB.CCC import *</div><div>>>> adapter1 = Adapter()</div><div>>>> adapter1.Function1()</div><div>u'AAA.BBB.CCC: Adapter Function1 Called'</div>
<div>>>> adapter1.Function2()</div><div>AAA.BBB.CCC: Adapter Function2</div><div>>>> network1 = Network()</div><div>>>> network1.Function1()</div><div>u'AAA.BBB.CCC: Network Function1 called'</div>
<div>>>> from AAA.CCC import *</div><div>>>> adapter1.Function1()</div><div>u'AAA.BBB.CCC: Adapter Function1 Called'</div><div>>>> adapter1 = Adapter()</div><div>>>> adapter1.Function1()</div>
<div>u'AAA.CCC: Adapter Function1 Called'</div><div>>>></div></div></div><div><br></div><div><div style>My questions are</div><div style><br></div><div style>1. I don't know how to specify different namespace of class when creating an instance.</div>
<div>2. The class that I already have has similar above layout in a project. Common project has many class files in it, and each class has different name space and class name.</div></div><div><div style>AddReference('Common') looks working and loaded, but can't import.</div>
<div style><br></div><div>>>> clr.AddReference('Common')</div><div><System.Reflection.RuntimeAssembly object at 0x052E73C8></div><div>>>> from Network import *</div><div>Traceback (most recent call last):</div>
<div> File "<stdin>", line 1, in <module></div><div>ImportError: No module named Network</div><div>>>> from Network.Common import *</div><div>Traceback (most recent call last):</div><div> File "<stdin>", line 1, in <module></div>
<div>ImportError: No module named Network.Common</div><div>>>></div></div><div style><br></div><div style>Difference is that Common project has [Serializable] and enabled "Make assembly COM-Visible"<br>
</div><div style><br></div><div style><div> [Serializable]</div><div> [Description("SimpleDictionary")] </div><div> public class SimpleDictionary : ISimpleDictionary</div><div> {</div><div> ...</div>
<div> }</div></div><div style><div><br></div><div style>Any thoughts?</div></div><div style>Wonder if there is a way to list available class after AddReference().</div><div style><br></div><div style>Thanks,</div><div style>
Spark.</div><div style><br></div></div></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Thu, Apr 18, 2013 at 9:14 PM, Stephen P. Lepisto <span dir="ltr"><<a href="mailto:stephenp@otakuworld.com" target="_blank">stephenp@otakuworld.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div text="#000000" bgcolor="#FFFFFF">
Try this from python with pythonNet installed (the current directory
is assumed to contain Adapter.dll):<br>
<br>
import clr<br>
clr.AddReference("Adapter") # Load the Adapter.dll<br>
from AAA.BBB import Adapter # Get the Adapter class type<br>
adapter = Adapter() # Create instance of the Adapter class<br>
adapter.GetSpeed() # Call the method<div><div class="h5"><br>
<br>
<br>
<div>On 4/18/2013 3:42 PM, Seungweon Park
wrote:<br>
</div>
<blockquote type="cite">
<div dir="ltr">Thank you for the reply.
<div><br>
</div>
<div>I did</div>
<div><br>
</div>
<div>
<div>>>> import clr</div>
<div>>>> from System.Reflection import Assembly</div>
<div>>>> Assembly.LoadWithPartialName("Adapter")</div>
<div><System.Reflection.RuntimeAssembly object at
0x05381148></div>
<div>>>> from AAA.BBB import Adapter</div>
<div>Traceback (most recent call last):</div>
<div> File "<stdin>", line 1, in <module></div>
<div>ImportError: No module named AAA.BBB</div>
</div>
<div><br>
</div>
<div>I don't know why I got this. :-(</div>
<div>Any idea?</div>
<div><span style="font-family:arial,sans-serif;font-size:13px">
<div><br>
</div>
</span></div>
</div>
<div class="gmail_extra"><br>
<br>
<div class="gmail_quote">On Thu, Apr 18, 2013 at 3:07 PM,
msutton <span dir="ltr"><<a href="mailto:msutton@ucsd.edu" target="_blank">msutton@ucsd.edu</a>></span>
wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div bgcolor="#FFFFFF" text="#000000">
<div>What I use is:<br>
<br>
import clr<br>
from System.Reflection import Assembly<br>
Assembly.LoadWithPartialName('Demo')<br>
from Render import Demo<br>
<br>
where the C# code has namespace Render and public class
Demo.<br>
<br>
-Manuel
<div>
<div><br>
<br>
On 04/18/2013 02:45 PM, Seungweon Park wrote:<br>
</div>
</div>
</div>
<blockquote type="cite">
<div>
<div>
<div dir="ltr">Hi,
<div><br>
</div>
<div>I have Adapter.dll with namespace
'AAA.BBB.Adapter" written in C# which gives
network adapter information.</div>
<div>I want to call one of method GetSpeed(). I
don't know How to create an instance in python.</div>
<div>Would you give me some clue for writing the
same python code like below powershell script
using <a href="http://python.net" target="_blank">python.net</a></div>
<div>I don't see any sample code which python
creates C# class instance.</div>
<div><br>
</div>
<div><br>
</div>
<div>Python</div>
<div>---------------------------</div>
<div>
<div>C:\CVS\Pythonnet>npython</div>
<div>Python 2.7.3 (default, Apr 10 2012,
23:31:26) [MSC v.1500 32 bit (Intel)] on win32</div>
<div>Type "help", "copyright", "credits" or
"license" for more information.</div>
<div>>>> import os,sys</div>
<div>>>>
sys.path.append("c:\\cvs\\powershelliteexample\\networktestlibrary\\iteextensions")</div>
<div>>>> sys.path</div>
<div>['',
'C:\\Python27\\lib\\site-packages\\paramiko-1.10.0-py2.7.egg',
'C:\\CVS\\Python\\libs',
'C:\\Windows\\system32\\pyt</div>
<div>hon27.zip', 'C:\\Python27\\Lib',
'C:\\Python27\\DLLs',
'C:\\Python27\\Lib\\lib-tk',
'C:\\CVS\\Pythonnet', 'C:\\Python27'</div>
<div>, 'C:\\Python27\\lib\\site-packages',
'C:\\Windows\\Microsoft.NET\\Framework\\v4.0.30319\\',
'c:\\cvs\\powershelliteexam</div>
<div>ple\\networktestlibrary\\iteextensions']</div>
<div>>>> import clr</div>
<div>>>> clr.FindAssembly("Adapter")</div>
<div>u'c:\\cvs\\powershelliteexample\\networktestlibrary\\iteextensions\\Adapter.dll'</div>
<div>>>> clr.AddReference("Adapter")</div>
<div><System.Reflection.RuntimeAssembly
object at 0x052028A0></div>
</div>
<div><br>
</div>
<div>I don't know how to create an instance of
Adapter.</div>
<div><br>
</div>
<div><br>
</div>
<div> Thank you,</div>
<div>Spark. </div>
<div>
<div><br>
</div>
<div><br>
</div>
<div>Powershell</div>
<div>----------------------------</div>
<div>PS C:\CVS\PowershellITEExample>
Import-Module .\LoadAdapter.psd1<br>
</div>
<div>PS C:\CVS\PowershellITEExample> $adapter
= New-object -type "AAA.BBB.Adapter"</div>
<div>PS C:\CVS\PowershellITEExample> $ret =
$adapter.GetAdapter("TestAdapter", "oids.xml")</div>
<div>PS C:\CVS\PowershellITEExample>
$ret.Passed</div>
<div>True</div>
<div>PS C:\CVS\PowershellITEExample>
$baseAdapter = $ret.FunctionReturnValue</div>
<div>PS C:\CVS\PowershellITEExample>
$baseAdapter.GetSpeed()</div>
<div><br>
</div>
<div>Passed : True</div>
<div>Failed : False</div>
<div>Errored : False</div>
<div>Status : Pass</div>
<div>Description : Speed retrieved
successfully.</div>
<div>FunctionReturnValue : auto</div>
</div>
</div>
<br>
<fieldset></fieldset>
<br>
</div>
</div>
<pre>_________________________________________________
Python.NET mailing list - <a href="mailto:PythonDotNet@python.org" target="_blank">PythonDotNet@python.org</a>
<a href="http://mail.python.org/mailman/listinfo/pythondotnet" target="_blank">http://mail.python.org/mailman/listinfo/pythondotnet</a></pre>
</blockquote>
<br>
</div>
</blockquote>
</div>
<br>
</div>
<br>
<fieldset></fieldset>
<br>
<pre>_________________________________________________
Python.NET mailing list - <a href="mailto:PythonDotNet@python.org" target="_blank">PythonDotNet@python.org</a>
<a href="http://mail.python.org/mailman/listinfo/pythondotnet" target="_blank">http://mail.python.org/mailman/listinfo/pythondotnet</a></pre>
</blockquote>
<br>
</div></div><span class="HOEnZb"><font color="#888888"><pre cols="72">--
Stephen P. Lepisto
</pre>
</font></span></div>
<br>_________________________________________________<br>
Python.NET mailing list - <a href="mailto:PythonDotNet@python.org">PythonDotNet@python.org</a><br>
<a href="http://mail.python.org/mailman/listinfo/pythondotnet" target="_blank">http://mail.python.org/mailman/listinfo/pythondotnet</a><br></blockquote></div><br></div>