FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Ensure a graceful exit if someone does something intentionally wrong … · pythonnet/pythonnet@69cd539 · GitHub

Commit 69cd539

Browse files
Barton Cline
committed
Ensure a graceful exit if someone does something intentionally wrong like call a non-static method on the class rather than on an instance of the class instead of an unhandled InvalidCastException.
1 parent eb27f97 commit 69cd539

1 file changed

Lines changed: 12 additions & 3 deletions

File tree

‎pythonnet/src/runtime/methodbinder.cs‎

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -294,9 +294,18 @@ internal Binding Bind(IntPtr inst, IntPtr args, IntPtr kw,
294294

295295
Object target = null;
296296
if ((!mi.IsStatic) && (inst != IntPtr.Zero)) {
297-
CLRObject co = (CLRObject)ManagedType.GetManagedObject(
298-
inst
299-
);
297+
//CLRObject co = (CLRObject)ManagedType.GetManagedObject(inst);
298+
// InvalidCastException: Unable to cast object of type
299+
// 'Python.Runtime.ClassObject' to type 'Python.Runtime.CLRObject'
300+
CLRObject co = ManagedType.GetManagedObject(inst) as CLRObject;
301+
302+
// Sanity check: this ensures a graceful exit if someone does
303+
// something intentionally wrong like call a non-static method
304+
// on the class rather than on an instance of the class.
305+
// XXX maybe better to do this before all the other rigmarole.
306+
if (co == null) {
307+
return null;
308+
}
300309
target = co.inst;
301310
}
302311

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL