Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Cannot load "System.Windows.Forms" when run demo\helloform.py if set PYTHONNET_RUNTIME=coreclr#2011

Unanswered
dasmine asked this question inQ&A
Discussion options

Environment

  • Pythonnet version: 3.0.1
  • Python version:3.9.2
  • Operating System: Windows 10
  • .NET Runtime: .Net 6

Details

We have some issues when load some asseblies which is built based on .net6 and some depedencies to system** binaries like "System.Drawing.Common".
Tried to add the dependecy path into %PATH%, not working:
Unhandled exception. System.BadImageFormatException: Could not load file or assembly 'System.Drawing.Common, Version=6.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. Reference assemblies should not be loaded for execution. They can only be loaded in the Reflection-only loader context. (0x80131058)

And found the same issue to run demo\helloform.py if set PYTHONNET_RUNTIME=coreclr

  1. set PYTHONNET_RUNTIME=coreclr
  2. python D:\pythonnet-master\demo\helloform.py

Traceback (most recent call last):
File "D:\pythonnet-master\demo\helloform.py", line 6, in
clr.AddReference("System.Windows.Forms")
System.IO.FileNotFoundException: Could not load file or assembly 'System.Windows.Forms, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified.
File name: 'System.Windows.Forms, Culture=neutral, PublicKeyToken=null'
at System.Reflection.RuntimeAssembly.InternalLoad(ObjectHandleOnStack assemblyName, ObjectHandleOnStack requestingAssembly, StackCrawlMarkHandle stackMark, Boolean throwOnFileNotFound, ObjectHandleOnStack assemblyLoadContext, ObjectHandleOnStack retAssembly)
at System.Reflection.RuntimeAssembly.InternalLoad(AssemblyName assemblyName, RuntimeAssembly requestingAssembly, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, AssemblyLoadContext assemblyLoadContext)
at System.Reflection.Assembly.Load(AssemblyName assemblyRef)
at Python.Runtime.AssemblyManager.LoadAssembly(AssemblyName name) in /tmp/build-via-sdist-dq4gmg3h/pythonnet-3.0.1/src/runtime/AssemblyManager.cs:line 227
at Python.Runtime.CLRModule.AddReference(String name) in /tmp/build-via-sdist-dq4gmg3h/pythonnet-3.0.1/src/runtime/Types/ClrModule.cs:line 107

You must be logged in to vote

Replies: 1 comment

Comment options

I managed to make it work on my side by providing aruntimeconfig.json that enforces the usage of the WindowsDesktop runtime.

{"runtimeOptions": {"tfm":"net6.0","rollForward":"LatestMinor","frameworks": [      {"name":"Microsoft.NETCore.App","version":"6.0.0"      },      {"name":"Microsoft.WindowsDesktop.App","version":"6.0.0"      }    ]  }}

You need to pass it the file path to thePYTHONNET_CORECLR_RUNTIME_CONFIG environment variable.

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

This discussion was converted from issue #2010 on November 17, 2022 10:08.


[8]ページ先頭

©2009-2025 Movatter.jp