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

pythonnet.load() fails with TypeError when supplying config_file#2212

cdfarrow started this conversation inGeneral
Discussion options

  • Pythonnet version: 3.0.1
  • Python version: 3.8 / 3.10
  • Operating System: Windows 11
  • .NET Runtime: 4.0

I'm using Python to use libraries from a large .NET application that has a host of dependency overrides in its .config file. I've been using pythonnet 2.5.2 successfully for quite some time and now trying to get it working with 3.0.1.
I'm trying to use pythonnet.load() to pass in the main application's .config file, but I'm getting a TypeError on the file name:

from pythonnet import loadload("netfx", config_file="mainapp.config")
Traceback (most recent call last):  File "C:\Users\Craig\AppData\Local\Programs\Python\Python310\lib\site-packages\pythonnet\__init__.py", line 73, in _create_runtime_from_spec    return clr_loader.get_netfx(**params)  File "C:\Users\Craig\AppData\Local\Programs\Python\Python310\lib\site-packages\clr_loader\__init__.py", line 168, in get_netfx    impl = NetFx(domain=domain, config_file=_maybe_path(config_file))  File "C:\Users\Craig\AppData\Local\Programs\Python\Python310\lib\site-packages\clr_loader\netfx.py", line 23, in __init__    self._domain = _FW.pyclr_create_appdomain(domain or ffi.NULL, config_file_s)TypeError: initializer for ctype 'char *' must be a bytes or list or tuple, not str

From what I can see it is not even getting to try opening the file (so the name/path is irrelevant for this bug report).

Key lines fromclr_loader.netfx.pyNetFx:__init__():

        if config_file is not None:            config_file_s = str(config_file)         self._domain = _FW.pyclr_create_appdomain(domain or ffi.NULL, config_file_s)

config_file comes in as aWindowPath and is cast tostr, however, it seems thatpyclr_create_appdomain() wants achar *

You must be logged in to vote

Replies: 1 comment 4 replies

Comment options

It tells you in the error right afterchar * that you must passbytes

You must be logged in to vote
4 replies
@cdfarrow
Comment options

But the code cited above fromnetfx.py changes it tostr, so me passing inbytes wouldn't help. Besides, bytes doesn't work because clr_loader.init.get_netfx() passes theconfig_file parameter throughPath() (in_maybe_path()), which expects astr (and converts it toWindowPath):

load("netfx", config_file=bytes("mainapp.exe.config", 'utf-8'))
Traceback (most recent call last):  File "C:\Users\Craig\AppData\Local\Programs\Python\Python38\lib\site-packages\pythonnet\__init__.py", line 73, in _create_runtime_from_spec    return clr_loader.get_netfx(**params)  File "C:\Users\Craig\AppData\Local\Programs\Python\Python38\lib\site-packages\clr_loader\__init__.py", line 148, in get_netfx    impl = NetFx(domain=domain, config_file=_maybe_path(config_file))  File "C:\Users\Craig\AppData\Local\Programs\Python\Python38\lib\site-packages\clr_loader\__init__.py", line 156, in _maybe_path    return Path(p)  File "C:\Users\Craig\AppData\Local\Programs\Python\Python38\lib\pathlib.py", line 1042, in __new__    self = cls._from_parts(args, init=False)  File "C:\Users\Craig\AppData\Local\Programs\Python\Python38\lib\pathlib.py", line 683, in _from_parts    drv, root, parts = self._parse_args(args)  File "C:\Users\Craig\AppData\Local\Programs\Python\Python38\lib\pathlib.py", line 672, in _parse_args    raise TypeError(TypeError: argument should be a str object or an os.PathLike object returning str, not <class 'bytes'>
@lostmsu
Comment options

Ah, I was hasty to convert it to a discussion. Still it seems to be a known unfixed bug:pythonnet/clr-loader#53

@lostmsu
Comment options

@filmor can argument passing be fixed separately? This error seems to be caused by the lack of encode calls you added in one of the commits inpythonnet/clr-loader#42

@filmor
Comment options

It can, but it doesn't help as the AppDomain generation is broken. That's why I didn't merge it, yet.

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Category
General
Labels
None yet
3 participants
@cdfarrow@filmor@lostmsu
Converted from issue

This discussion was converted from issue #2210 on August 05, 2023 18:52.


[8]ページ先頭

©2009-2025 Movatter.jp