Skip to content

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

@dasmine

Description

@dasmine

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions