InvalidOperationException with custom interpreter

Aug 10, 2011 at 5:57 PM

Hi,

In our application we include a custom python interpreter which, right now, is just a modified Console.cs with added references to our app libraries. Also bundled is a DLL with python standard library compiled with CompileModules(). Recently I've begun to play with PTVS but was unable to make it work with our interpreter. A one liner script fails with "System Error: Operación no válida dado el estado actual del objeto.\nPress any key to continue . . .". That's an InvalidOperationException in the Spanish Framework.

Of course the IPY 2.7 interpreter works fine. It's ours that not. The interpreter correctly runs the script under the CLI.

Are there any way to debug it?

Regards,

Hernán.

Editor
Aug 10, 2011 at 6:41 PM

Can you tell us how you configured your interpreter? Also, what sequence of actions are you taking to run your script?

Aug 10, 2011 at 7:03 PM

In Options / Python Tools / Interpreter Options, I've added an interpreter with its full path (the executable is name eccpy.exe), windows path left blank as we don't support pyw, architecture x86 and language version 2.7. Then I've marked it as the default one.

For the script, I've created a Python command line project, and edited Program.py by adding a couple of print calls. Then I've just hit the play button.

Aug 29, 2011 at 3:19 PM

Any news on this?

Did I answer what you've asked or misinterpret the question?

Editor
Aug 31, 2011 at 4:51 AM

Actually, I missed your second post the first time around, so I apologize for the slow response.

The first thing I'd suggest is to upgrade to 1.0, which was just released.  I think it's unlikely to solve the problem, but it means that I'll be able to open a bug against the current version.

The next thing will be to see if it launches with launch mode set to "IronPython (.NET) launcher" set in the Project->Properties->Debug pane. If this works, it narrows the problem down to our python debugger.

Finally we'll probably want you to launch it with another version of Visual Studio attached as a debugger and with symbols loaded, because that will help us pinpoint where the exception is coming from.

Thanks for your help, and your patience!

Aug 31, 2011 at 11:14 AM

It's working now, thanks!

I think the problem relates to a faulty installation of our interpreter because there some of the IPY related dlls were missing in its directory. I've also upgraded to version 1.0 and recreate the projects with IronPython type instead of Python type. Anyway, it's working fine so thanks again.

BTW, is it possible to install PythonTools *without* installing IronPython first? My plan is to tell our customers to install VS2010 + PythonTools and point the interpreter to ours if they want to debug their scripts.

Regards,

-Hernán.

Aug 31, 2011 at 11:24 AM
Edited Aug 31, 2011 at 11:25 AM

I've tested a bit more and when changed the launch mode to "Standard Python" the InvalidOperationException is thrown again.

An invalid path exception is also being raised now. This is the output:

 

Traceback (most recent call last):

  File "C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE\Extensions\Microsoft\Python Tools for Visual Studio\1.0\visualstudio_py_debugger.py", line 1296, in attach_process

    MODULES.append((filename, Module(path.abspath(filename))))

  File "ntpath", line 465, in abspathValueError: Specified path is invalid.

SystemError: Operación no válida dado el estado actual del objeto.

Press any key to continue . . .

Editor
Aug 31, 2011 at 11:32 AM

Yes, you can install PTVS without first installing IronPython; that should work fine.

That traceback is now coming from python code; can you add a print statement just before line 1296 in visualstudio_py_debugger.py which prints out the value of "filename", so we can see why it thinks it is invalid?

Aug 31, 2011 at 11:56 AM

Sure, here it is. I've enclosed the content of "filename" with "|" to see if there's whitespaces in it.

|C:\Windows\system32\site|
|C:\Windows\system32\_abcoll|
|weakref|
|C:\Windows\system32\warnings|
|C:\Windows\system32\abc|
|_weakrefset|
|C:\Windows\system32\types|
|sysconfig|
|C:\Windows\system32\stat|
|C:\Windows\system32\ntpath|
|C:\Windows\system32\ntpath|
|C:\Windows\system32\linecache|
|mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, System, 
Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, System.Windows.Forms, 
Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089|
Traceback (most recent call last):
  File "C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE\Extensions\Microsoft\
Python Tools for Visual Studio\1.0\visualstudio_py_debugger.py",
 line 1297, in attach_process
    MODULES.append((filename, Module(path.abspath(filename))))
  File "ntpath", line 465, in abspathValueError: Specified path is invalid.
|C:\Windows\system32\UserDict|
|traceback|
|C:\Windows\system32\os|
|C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE\Extensions\Microsoft\Python
Tools for Visual Studio\1.0\visualstudio_py_debugger.py|
|C:\Windows\system32\genericpath|
|C:\ProyectosVisualStudio\EjemploPython\EjemploECC3\BasicSample-1.py|
|struct|
SystemError: Operación no válida dado el estado actual del objeto.
Press any key to continue . . .
Editor
Aug 31, 2011 at 5:09 PM

Thanks for your help. I think this is enough for us to work on, and I've opened [workitem:494]  for this bug, so you'll want to track that workitem now.

Aug 31, 2011 at 5:28 PM

Thank you.

Meanwhile we can use IronPython launch mode so we have a workaround.

Editor
Aug 31, 2011 at 7:09 PM

As a workaround for yourself you can replace line 1296 in visualstudio_py_debugger.py with this:

try:
    fullpath = path.abspath(filename)
except:
    pass
else:
    MODULES.append((filename, Module(fullpath)))
If you are going to be distributing this to your users, instead of asking them to hack visualstudio_py_debugger.py you can move all imports of .Net namespaces (such as System.Windows.Forms) out of your site.py and into a startup script, then execute python -i startup.py.

Sep 1, 2011 at 9:37 AM

FWIW, the workaround for visualstudio_py_debugger.py fixes the invalid path exception but not the "SystemError: InvalidOperation".

PS: I've added this comment to the workitem:494.