pythonnet / pythonnet/pythonnet

It is illegal to reflect on the custom attributes of a Type loaded via ReflectionOnlyGetType

Open
#1,199 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C#
Stars
5.5k
Forks
780
PR merge metrics
No merged PRs in 30d

Description

Environment
  • Pythonnet version: 2.5.1
  • Python version: 3.8 (anaconda)
  • Operating System: Windows 10
Details
  • Describe what you were trying to get done.

    View C# object members in jupyter notebook (via dot tab). C# app crashes.

  • What commands did you run to trigger this issue?

    csharpObjectWithCustomAttributes.  # +tab in jupyter notebook should list members, but instead crashes

The c# library I am using is not publicly available. I assume it could be reproduced with some effort (creating an example C# library having an object with custom attributes).

However, I have found a related stack overflow issue (and solution): https://stackoverflow.com/a/42540881

And I see the potential "illegal use" in the code base here: https://github.com/pythonnet/pythonnet/search?q=GetCustomAttributes&unscoped_q=GetCustomAttributes

The fix might be to convert calls to GetCustomAttributes to what is mentioned in the stack overflow answer.

  • If there was a crash, please include the traceback here.

Traceback happens inside loaded DLL and application crashes. All I get is this:
image
TBH, that is one of the best error messages I've seen in a long time.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the repository search for GetCustomAttributes and compare those calls with the linked Stack Overflow solution. Reproduce the Jupyter notebook member-listing crash using a C# object with custom attributes; done means reflection no longer crashes when inspecting the object.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, jupyter-notebook, python
Domain
developer-experience
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.