Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exception while editing IronPython code #697

Closed
andygraham opened this issue Aug 7, 2015 · 6 comments
Closed

Exception while editing IronPython code #697

andygraham opened this issue Aug 7, 2015 · 6 comments
Assignees
Labels
Milestone

Comments

@andygraham
Copy link

VS2013 Desktop Express, IronPython 2.7.5, PTVS 2.2.30718.00

Occasionally while editing IronPython code I get a modal MessageBox telling me that
"An exception has been encountered. This may be caused by an extension."

The relevant entry in the VS activity log starts

System.InvalidCastException: Unable to cast object of type 'IronPython.Runtime.Types.BuiltinFunction' to type 'IronPython.Runtime.Types.PythonType'. at
Microsoft.IronPythonTools.Interpreter.RemoteInterpreter.<>c__DisplayClass64_0.b__0() at Microsoft.IronPythonTools.Interpreter.RemoteInterpreter.CallAndHandle[T](Func`1 action, T defaultValue) at
Microsoft.IronPythonTools.Interpreter.RemoteInterpreter.GetPythonTypeMemberType(ObjectIdentityHandle pythonType) at
Microsoft.IronPythonTools.Interpreter.RemoteInterpreterProxy.GetPythonTypeMemberType(ObjectIdentityHandle value) at
Microsoft.IronPythonTools.Interpreter.RemoteInterpreterProxy.GetPythonTypeMemberType(ObjectIdentityHandle value) at
Microsoft.IronPythonTools.Interpreter.IronPythonType.get_MemberType() at
Microsoft.PythonTools.Analysis.Values.BuiltinClassInfo.get_MemberType() at
Microsoft.PythonTools.Analysis.Values.SpecializedNamespace.get_MemberType() at
Microsoft.PythonTools.Analysis.MemberResult.GetMemberType() at
Microsoft.PythonTools.Analysis.MemberResult.get_MemberType() at
Microsoft.PythonTools.Intellisense.CompletionAnalysis.PythonCompletion(IGlyphService service, MemberResult memberResult) at
...

Unfortunately I can't see any way of attaching the activity log here.

@andygraham
Copy link
Author

Also, while rebuilding a combined C# and IronPython solution, I occasionally get a total freeze of VS with a dialog message "Microsoft Visual Studio Express 2013 for Windows Desktop has stopped working" with the following problem signature that is also a cast exception. Nothing has been added to the activity log.

Problem signature:
Problem Event Name: CLR20r3
Problem Signature 01: WDExpress.exe
Problem Signature 02: 12.0.40629.0
Problem Signature 03: 5590c29f
Problem Signature 04: Microsoft.PythonTools.IronPython.Interpreter
Problem Signature 05: 2.2.30718.0
Problem Signature 06: 55aadecd
Problem Signature 07: 205
Problem Signature 08: 0
Problem Signature 09: System.InvalidCastException
OS Version: 6.1.7601.2.1.0.768.3
Locale ID: 2057
Additional Information 1: 0a9e
Additional Information 2: 0a9e372d3b4ad19135b953a78882e789
Additional Information 3: 0a9e
Additional Information 4: 0a9e372d3b4ad19135b953a78882e789

@zooba zooba added this to the 2.2.1 milestone Aug 7, 2015
@zooba zooba self-assigned this Aug 7, 2015
@zooba
Copy link
Member

zooba commented Aug 7, 2015

That's totally okay, the stack trace is more than enough information for us here.

(The best way to provide a big text file on GitHub is to create a https://gist.github.com/ and link to it.)

@zooba
Copy link
Member

zooba commented Aug 7, 2015

We should also backport this fix to 2.1.1.

@zooba
Copy link
Member

zooba commented Aug 7, 2015

So I started fixing this but have to get onto something else right now. Here are the changes I've made so far, and there are a lot more unconditional casts that now need to be checked properly (I assume IronPython 2.7.5 changed the base types of some types).

diff --git a/Python/Product/IronPython/Interpreter/RemoteInterpreter.cs b/Python/Product/IronPython/Interpreter/RemoteInterpreter.cs
--- a/Python/Product/IronPython/Interpreter/RemoteInterpreter.cs
+++ b/Python/Product/IronPython/Interpreter/RemoteInterpreter.cs
@@ -702,7 +702,18 @@

         internal PythonMemberType GetPythonTypeMemberType(ObjectIdentityHandle pythonType) {
             return CallAndHandle(() => {
-                var value = (PythonType)Unwrap(pythonType);
+                var pt = Unwrap(pythonType);
+                var value = pt as PythonType;
+                if (value == null) {
+                    if (pt is BuiltinFunction) {
+                        return PythonMemberType.Function;
+                    }
+                    if (pt is BuiltinMethodDescriptor) {
+                        return PythonMemberType.Method;
+                    }
+                    Debug.Fail("Unhandled IronPython type: " + pt.GetType().FullName);
+                    return PythonMemberType.Unknown;
+                }
                 var type = value.__clrtype__();
                 if (type.IsEnum) {
                     return PythonMemberType.Enum;
@@ -716,8 +727,8 @@

         internal bool PythonTypeHasNewOrInitMethods(ObjectIdentityHandle pythonType) {
             return CallAndHandle(() => {
-                var value = (PythonType)Unwrap(pythonType);
-                return PythonTypeHasNewOrInitMethods(value);
+                var value = Unwrap(pythonType) as PythonType;
+                return value != null && PythonTypeHasNewOrInitMethods(value);
             }, false);
         }

@zooba zooba removed their assignment Aug 7, 2015
@andygraham
Copy link
Author

I do hope this is fixed soon. As my project is growing the constant freezing of VS during compilation is getting tedious to the point of being almost unusable.

@zooba zooba self-assigned this Aug 19, 2015
@zooba
Copy link
Member

zooba commented Aug 19, 2015

Having looked deeper into this, I don't think handling all the types is actually the correct approach. It looks more like we're creating an IronPythonType object around something (probably from a managed DLL) that isn't actually represented by a PythonType within IronPython. I suspect the function below from IronPythonInterpreter.cs is to blame:

        internal IPythonType GetTypeFromType(ObjectIdentityHandle type) {
            if (type.IsNull) {
                return null;
            }

            lock (this) {
                IMember res;
                if (!_members.TryGetValue(type, out res)) {
                    _members[type] = res = new IronPythonType(this, type);
                }
                return res as IPythonType;
            }
        }

But it's called from a lot of places. @DinoV might be able to track down the incorrect one faster than I can.

@zooba zooba assigned zooba and unassigned zooba Aug 19, 2015
zooba added a commit that referenced this issue Aug 21, 2015
Fixes #697 Exception while editing IronPython code
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants