[python-win32] makepy problem with a .Net assembly => COM

Dan Kruger Dan.Kruger@vancoservices.com
Fri, 14 Feb 2003 15:41:39 -0600


Dan Kruger wrote:
--------------------------
Hello!

I'm new to .Net, and Python, so please forgive me in advance if I sound =
rather inexperienced..

I've been building a set of tools for the programming staff where I work =
to provide simple access to some of the
more complexities behind accessing a MySQL server with a dedicated data =
provider as well as some of the business rules..

Internal processing programs will be using the .Net assemblies I've =
produced, but our web content is mostly created with
Python (thru CGI scripting) because it's a far easier for the web-designers=
 to comprehend.

Currently, there has been functions written to emulate the functionality =
of the .Net assemblies, which could potentially create a maintenance =
headache if business policies were to change.. (i.e. the python functions =
would have to be updated along side the .Net functions)

So.. what I'd like to do is use the .Net assemblies in the Python scripts =
so that all data processing is going through the same engine.

Anyway.. here are the steps I've gone through to make this happen, and =
here's the problem I'm experiencing:
I ...
1)  compiled the assembly=20
2) placed it in the same directory as the python interpretter
3) regasm /tlb'ed the assembly.

>>> import win32com.client
Rebuilding cache of generated files for COM support...
Done.
>>> a =3D win32com.client.Dispatch("DotNetSystemTools.ByteFXDataAccess.clsM=
ySQLQueryExecute")
>>> print a.Execute("SELECT NOW()",0)
Traceback (most recent call last):
  File "<interactive input>", line 1, in ?
  File "<COMObject DotNetSystemTools.ByteFXDataAccess.clsMySQLQueryExecute>=
", line 2, in Execute
com_error: (-2147352567, 'Exception occurred.', (0, 'DotNetSystemTools', =
'Object reference not set to an instance of an object.', None, 0, =
-2147467261), None)


So.. I run the makepy utility..  I get...

>>> Generating to C:\Python22\lib\site-packages\win32com\gen_py\F9CBB761-13=
89-4044-87AC-F68E4286CD02x0x1x0.py

Now when I try to reference the COM object I get...

>>> a =3D win32com.client.Dispatch("DotNetSystemTools.ByteFXDataAccess.clsM=
ySQLQueryExecute")
>>> print a.Execute("SELECT NOW()",0)
Traceback (most recent call last):
  File "<interactive input>", line 1, in ?
  File "C:\Python22\lib\site-packages\win32com\client\__init__.py", line =
368, in __getattr__
    raise AttributeError, "'%s' object has no attribute '%s'" % (repr(self)=
, attr)
AttributeError: '<win32com.gen_py.F9CBB761-1389-4044-87AC-F68E4286CD02x0x1x=
0._DotNetSystemTools_ByteFXDataAccess_clsMySQLQueryExecute>' object has no =
attribute 'Execute'

I got no warnings when I built the tlb files with regasm.  Any idea why =
this won't go from the meager amount of information I've given here.  (I =
would probably be able to supply the source)

The assembly does have some 3rd party reference .dlls (I believe the =
author wrote these in C# managed code).  Would this make a difference?  =
I'm guessing it wouldn't since there are NO direct interfaces to these 3rd =
party interfaces are public (just function/property wrappers I've written =
that hand the data off).
=AF-------------------

Ok.. I managed (no pun intended) to get the object to create with the =
first method.. (word to the wise, when you declare a string in vb.net, =
instead of setting it to "", it sets it to Nothing.  Be prepared to handle =
an error when a string is Nothing if you don't initialize it to ""  ;)  )

Here's the weird thing.  Under that "Execute" function, an .ExecuteScalar =
is being called, and SHOULD return a value.

I'm always getting "None" returned to python.  (Execute function returns =
an "Object" datatype, which should convert to the appropriate type when =
returned)

Any ideas?

Thanks in advance
Dan