GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — PythonEngine fails to initialize in VSIX extension · pythonnet/pythonnet · Discussion #2405

PythonEngine fails to initialize in VSIX extension #2405

Closed Answered by cpgames
cpgames asked this question in Q&A
PythonEngine fails to initialize in VSIX extension #2405
@cpgames cpgames
Jun 22, 2024 · 2 comments
Answered by cpgames Return to top
Discussion options
  • Uh oh!

    There was an error while loading. Please reload this page.

cpgames
Jun 22, 2024

Environment

  • Pythonnet version: 3.0.3, 3.1.0
  • Python version: 3.09
  • Operating System: Win11
  • .NET Runtime: 4.8

Details

  • Describe what you were trying to get done.

I am trying to use pythonnet package in a VSIX Visual Studio extension.
The Experimental VS Instance initializes pythonnet fine, however deploying an extension causes this crash.
I suspect there may be some threading issues, but am not sure what to look for.

  • What commands did you run to trigger this issue? If you can provide a
    Minimal, Complete, and Verifiable example
    this will help us understand the issue.
try
{
    Runtime.PythonDLL = pythonFile.FullName;
    PythonEngine.PythonHome = pythonFile.DirectoryName!;
    OutputWindowHelper.LogInfo("PythonEngine", "Initializing Python engine.");
    PythonEngine.Initialize(); // crash here
    PythonEngine.BeginAllowThreads();
}
catch (Exception ex)
{
    OutputWindowHelper.LogError(ex);
}
  • If there was a crash, please include the traceback here.
[INFO] - PythonEngine: Initializing Python engine.
[ERROR]: Object reference not set to an instance of an object.
[TRACE]:    at Python.Runtime.ClassManager.GetClassInfo(Type type, ClassBase impl)
   at Python.Runtime.ClassManager.InitClassBase(Type type, ClassBase impl, ReflectedClrType pyType)
   at Python.Runtime.ReflectedClrType.GetOrCreate(Type type)
   at Python.Runtime.ModuleObject.GetAttribute(String name, Boolean guess)
   at Python.Runtime.ModuleObject.LoadNames()
   at Python.Runtime.ImportHook.UpdateCLRModuleDict()
   at Python.Runtime.PythonEngine.Initialize(IEnumerable`1 args, Boolean setSysArgv, Boolean initSigs)
   at Python.Runtime.PythonEngine.Initialize()
   at cpGames.VSA.ToolAPI.<InitializePythonEngineAsync>d__2.MoveNext() in ToolAPI.cs:line 69 // PythonEngine.Initialize(); call
You must be logged in to vote
All reactions
Answered by cpgames Jun 23, 2024

Why you close my issue?

Here's your fix:

internal static bool ShouldBindEvent(EventInfo ei)
        {
            var mb = ei.GetAddMethod(true);
            if (mb == null)
            {
                return false;
            }
            return ShouldBindMethod(mb);
        }

Check your nulls, thank me later.

View full answer

Replies: 2 comments

Comment options
  • Uh oh!

    There was an error while loading. Please reload this page.

  • Uh oh!

    There was an error while loading. Please reload this page.

cpgames
Jun 23, 2024
Author

Why you close my issue?

Here's your fix:

internal static bool ShouldBindEvent(EventInfo ei)
        {
            var mb = ei.GetAddMethod(true);
            if (mb == null)
            {
                return false;
            }
            return ShouldBindMethod(mb);
        }

Check your nulls, thank me later.

You must be logged in to vote
All reactions
  • 👀 1
0 replies
Answer selected by cpgames
Comment options
  • Uh oh!

    There was an error while loading. Please reload this page.

  • Uh oh!

    There was an error while loading. Please reload this page.

adrctr
Jul 8, 2024

Hello ,

I have the same issue, I am trying to use pythonnet package in a VSIX Visual Studio extension.

image

I am going to apply this fix above made by @cpgames and see if the problem persists.

Do you intend to release this fix in a future version of pythonnet ?

Regards,

You must be logged in to vote
All reactions
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
🙏
Q&A
Labels
None yet
2 participants
@cpgames @adrctr
Converted from issue

This discussion was converted from issue #2404 on June 23, 2024 07:54.

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.