You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When I was trying to setup configuration file for the py script I am running to call my .Net assembly, I've got this error:
Traceback (most recent call last):
File "C:\Program Files\Python310\lib\site-packages\pythonnet\__init__.py", line 73, in _create_runtime_from_spec
return clr_loader.get_netfx(**params)
File "C:\Program Files\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:\Program Files\Python310\lib\site-packages\clr_loader\netfx.py", line 27, in __init__
self._domain = _FW.pyclr_create_appdomain(domain_s, config_file_s)
TypeError: initializer for ctype 'char *' must be a bytes or list or tuple, not str
As it appears the pyclr_create_appdomain end point expects LPUTF8Str and not LPStr.
That raises number of issues on its own - such as what if my config file is located inside the Unicode named path - but immediate problem was in the code:
initialize()
if config_file is not None:
config_file_s = str(config_file) #.encode()
else:
config_file_s = ffi.NULL
self._domain_name = domain
self._config_file = config_file
if domain is not None:
domain_s = domain #.encode()
else:
domain_s = ffi.NULL
self._domain = _FW.pyclr_create_appdomain(domain_s, config_file_s)
As you could see I made a local fix adding .encode() call before passing parameters to the end point.
Questions:
Am I doing something wrong? Here is my code below:
import os
from pathlib import Path
config_file = r"D:\_WorkRoot\Tests\Python_ASR\Diarization\_Examples\Enrichment\sctlib.py.config"
#os.environ["PYTHONNET_NETFX_CONFIG_FILE"] = config_file
config_path = Path(config_file)
from pythonnet import set_runtime
#set_runtime("netfx", domain="sctlib_py", config_file=config_path)
set_runtime("netfx", domain="sctlib_py")
It took me awhile to recognize I don't need to construct Path inside my script and passing string from my end works too. But in your code, you take my string, convert to Path only to convert it back to string. Maybe to validate the path exists? Just a comment.
I made a local change adding .encode() call to by-pass the error. What you want me to do? Abandon that - since you already addresses that, keep my local changes (and remember maintaining that on different machines) or to apply the fix to the repo (I have not done such contributions before, so I simply don't know the customary procedures).
Thanks.
The text was updated successfully, but these errors were encountered:
When I was trying to setup configuration file for the py script I am running to call my .Net assembly, I've got this error:
As it appears the
pyclr_create_appdomain
end point expects LPUTF8Str and not LPStr.That raises number of issues on its own - such as what if my config file is located inside the Unicode named path - but immediate problem was in the code:
As you could see I made a local fix adding
.encode()
call before passing parameters to the end point.Questions:
It took me awhile to recognize I don't need to construct Path inside my script and passing string from my end works too. But in your code, you take my string, convert to Path only to convert it back to string. Maybe to validate the path exists? Just a comment.
I made a local change adding .encode() call to by-pass the error. What you want me to do? Abandon that - since you already addresses that, keep my local changes (and remember maintaining that on different machines) or to apply the fix to the repo (I have not done such contributions before, so I simply don't know the customary procedures).
Thanks.
The text was updated successfully, but these errors were encountered: