[Python.NET] Calling C# from Python 2.3

Amod Kulkarni amod.kulkarni at neilsoft.com
Mon Jan 3 08:37:32 CET 2005


Hi,

I know PythonNet has been specially designed to handle .NET/CLR
compatibility but because of some other restrictions I want to use Python
2.3 to access a C# function.
First of all is it possible? I am trying with following piece of code in C#
(Server app) and python (client app).



This is a class library in C# which is compiled and registered with
following commands.
csc /target:library Class1.cs
regasm Try2005.dll /tlb:Try2005.tlb


using System;
using System.Runtime.InteropServices;

namespace Try2005
{
      public class TestingCSBC
      {
            [Guid("1EB394AB-2D4A-4a52-9F22-E8ACAED4800F")]
                  public interface IManagedInterface
            {
                  int PrintHi(string name);
            }

            [Guid("2FD76301-489A-4dc3-BF6B-5DF6FCE96CB8")]
                  public class InterfaceImplementation : IManagedInterface
            {
                  public int PrintHi(string name)
                  {
                        Console.WriteLine("Hello, {0}!", name);
                        //TestCSBCClass obj = new
TESTDLLCOMLib.TestCSBCClass();
                        //obj.Displaymessage("In C# application!!");
                        return 33;
                  }
            }
      }
}


Python code:

import win32com.client
try:
    serverObj = win32com.client.Dispatch("Try2005.TestingCSBC")
except Exception,e:
    print "Dispatch error",e
try:
    serverObj.PrintHi("But will it work on Tribon??")
except Exception,e:
    print "Error while Calling C# function",e


After running the above Py script I am getting following error output.

Dispatch error (-2147024894, 'The system cannot find the file specified.',
None, None)
Error while Calling C# function name 'serverObj' is not defined


Any pointers would be greatly appreciated.

Thanks in advance.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/pythondotnet/attachments/20050103/bbec1a95/attachment-0001.htm


More information about the PythonDotNet mailing list