[Python.NET] accessing .net dlls from python

Hernan Martinez Foffani hernan.martinez at ecc.es
Wed Mar 29 11:30:42 CEST 2006


>> import CLR
>> from CLR.System.Reflection import Assembly
>> 
>> my_dll_name = Assembly.LoadWithPartialName( path to dll that does
>> not include .dll extension ) 
>> 
>> #import namespaces
>> from CLR import TopNamespace
>
> 1.  Installing Python for .NET as a standalone, and using it in the
> interactive session, all of the above, apart from 'from CLR import
> TopNamespace' works.  'from CLR import TopNamespace' gets
> 'ImportError: cannot import name TopNamespace'.

If your C# source file contains something along the lines of:
    
    namespace MyLib { public class MyClass { ... } }

and, say, is compiled to a DLL called A_LIB.DLL and placed
in your current directory, then in python.net it would be:

    from CLR.System.Reflection import Assembly
    a = Assembly.LoadWithPartialName("A_LIB")
    from CLR.MyLib import MyClass

-H.



More information about the PythonDotNet mailing list