Note: the question was originally about Python and win32com
, but it turns out that the issue exists within the COM server, not the client-side. Therefore the information in the question and the answer are applicable to all languages that are usable as COM clients.
Maybe someone can help out. What I am facing is the following situation. I can instantiate VisualStudio.VCProjectEngine.8.0
just fine with my code. The relevant code:
import win32com
vcver = {
'VisualStudio.VCProjectEngine.8.0' : ('{FBBF3C60-2428-11D7-8BF6-00B0D03DAA06}', 0, 8, 0),
'VisualStudio.VCProjectEngine.10.0' : ('{0CD36BB6-D828-4DB9-91BF-AD493EE76B79}', 0, 10, 0),
}
for ProgID, vc in vcver.iteritems():
# Error also happens without the following line
win32com.client.gencache.EnsureModule(vc[0], vc[1], vc[2], vc[3])
o = win32com.client.gencache.GetClassForProgID(ProgID)()
if o:
try:
# The following line causes the exception ...
o.CreateProject('test')
print "Success for %s" % ProgID
except Exception as e:
print str(e)
raise
... gives this error:
Success for VisualStudio.VCProjectEngine.8.0
(-2147352567, 'Exception occurred.', (0, u'mscorlib', u"Could not find a part of the path 'C:\\Python27\\ProjectComponents'.", None, 0, -2147024893), None)
Traceback (most recent call last):
File "D:\scriptname.py", line 123, in <module>
o.CreateProject('test')
File "C:\Users\Username\AppData\Local\Temp\gen_py\2.7\0CD36BB6-D828-4DB9-91BF-AD493EE76B79x0x10x0.py", line 2756, in CreateProject
ret = self._oleobj_.InvokeTypes(213, LCID, 1, (9, 0), ((8, 1),),projectName
pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, u'mscorlib', u"Could not find a part of the path 'C:\\Python27\\ProjectComponents'.", None, 0, -2147024893), None)
So as you can see, one works fine and the other fails mysteriously. What gives?
Here's what makepy.py -i
gives:
>makepy.py -i VisualStudio.VCProjectEngine.8.0
VCProjectEngineLibrary
{FBBF3C60-2428-11D7-8BF6-00B0D03DAA06}, lcid=0, major=8, minor=0
>>> # Use these commands in Python code to auto generate .py support
>>> from win32com.client import gencache
>>> gencache.EnsureModule('{FBBF3C60-2428-11D7-8BF6-00B0D03DAA06}', 0, 8, 0)
>makepy.py -i VisualStudio.VCProjectEngine.10.0
VCProjectEngineLibrary
{0CD36BB6-D828-4DB9-91BF-AD493EE76B79}, lcid=0, major=10, minor=0
>>> # Use these commands in Python code to auto generate .py support
>>> from win32com.client import gencache
>>> gencache.EnsureModule('{0CD36BB6-D828-4DB9-91BF-AD493EE76B79}', 0, 10, 0)
Note: I just noticed that the CLSID given by makepy.py -i
matches for VisualStudio.VCProjectEngine.8.0
, but not for VisualStudio.VCProjectEngine.10.0
(where the registry shows {4547a58d-fc1c-4502-84fa-0163ee766635}
):
However, even adjusting the tuple for VisualStudio.VCProjectEngine.10.0
to be ('{4547a58d-fc1c-4502-84fa-0163ee766635}', 0, 10, 0)
doesn't help with the exception.
The error appears to be with Visual Studio 2010 and later. I also tried VisualStudio.VCProjectEngine.11.0
and VisualStudio.VCProjectEngine.12.0
as ProgID with the values given by makepy.py -i
, but the errors were similar:
Error for VisualStudio.VCProjectEngine.11.0: (-2147352567, 'Exception occurred.', (0, u'mscorlib', u"Could not find a part of the path 'C:\\Python27\\ProjectComponents'.", None, 0, -2147024893), None)
Error for VisualStudio.VCProjectEngine.10.0: (-2147352567, 'Exception occurred.', (0, u'mscorlib', u"Could not find a part of the path 'C:\\Python27\\ProjectComponents'.", None, 0, -2147024893), None)
Error for VisualStudio.VCProjectEngine.12.0: (-2147352567, 'Exception occurred.', (0, u'mscorlib', u'One or more errors occurred.', None, 0, -2146233088), None)