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 — System.ArgumentException: Illegal characters in path · Issue #2376 · pythonnet/pythonnet

System.ArgumentException: Illegal characters in path #2376

New issue
Copy link
New issue
Copy link
Closed
#2383
Closed
System.ArgumentException: Illegal characters in path#2376
#2383
Copy link

Description

@manju1847
manju1847
opened on May 7, 2024
Issue body actions

Environment

  • Pythonnet version: 3.0.3
  • Python version: 3.10.11
  • Operating System: Windows 10
  • .NET Runtime: 4.5

Details

  • Trying to load DLL using AddReference.

import clr
clr.AddReference("C:\MyProject\TestFolder_Dependencies\MyDLLProject\Test.TA.MyVersion.Test.dll")

System.ArgumentException: Illegal characters in path.
at System.IO.Path.CheckInvalidPathChars(String path, Boolean checkAdditional)
at System.IO.Path.Combine(String path1, String path2)
at Python.Runtime.AssemblyManager.d__15.MoveNext()
at System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable`1 source)
at Python.Runtime.AssemblyManager.LoadAssemblyPath(String name)
at Python.Runtime.CLRModule.AddReference(String name)

DLL is not a new implementation. Same DLL and same path was working fine with python 3.7 and PythonNET 2.4.0. This issue started happening when we upgraded python and Pythonnet versions.

Activity

  1. filmor commented on May 7, 2024

    @filmor
    filmor
    on May 7, 2024
    Member
    More actions

    This is not a support forum. If you are using backslashes in strings in Python (and really, almost all programming languages) you have to either escape them or use a raw string literal.In Python that would be r"blabla\blubb".

  2. filmor
    closed this as not plannedon May 7, 2024
  3. manju1847 commented on May 7, 2024

    @manju1847
    manju1847
    on May 7, 2024
    Author
    More actions

    Sorry it was a typo. Yes, I have escaped the back slash. Its nothing to do with backslash. Because same code works fine when tested with python 3.7 and PythonNET 2.4.0.

  4. manju1847 commented on May 10, 2024

    @manju1847
    manju1847
    on May 10, 2024
    Author
    More actions

    Tried to load the same DLL using Assembly.LoadFrom(path) - this works without any issues. But clr.AddReference(path) throws Illegal characters in path exception.

    from System.Reflection import Assembly
    assembly = Assembly.LoadFrom(path)

  5. lostmsu commented on May 10, 2024

    @lostmsu
    lostmsu
    on May 10, 2024
    Member
    More actions

    @manju1847 can you share your sys.path? I suspect we stumble on something funky there.

  6. manju1847 commented on May 10, 2024

    @manju1847
    manju1847
    on May 10, 2024
    Author
    More actions

    echo %PATH%
    C:\Program Files\IcedTeaWeb\WebStart\bin;C:\Program Files\Zulu\zulu-8-jre\bin;C:\Program Files (x86)\Zulu\zulu-8-jre\bin;C:\Program Files\Python310\Scripts;C:\Program Files\Python310;C:\Users\fnh3651\AppData\Local\Programs\Python\Python37-32;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0;C:\WINDOWS\System32\OpenSSH;C:\Program Files\dotnet;C:\Users\fnh3651.dnx\bin;C:\Program Files\Microsoft DNX\Dnvm;C:\Program Files\Microsoft SQL Server\130\Tools\Binn;C:\Program Files (x86)\Windows Kits\10\Windows Performance Toolkit;C:\Program Files\Microsoft VS Code\bin;C:\Users\fnh3651\AppData\Local\Programs\Python\Python310\Scripts;C:\Users\fnh3651\AppData\Local\Programs\Python\Python310;C:\Users\fnh3651\AppData\Local\Programs\Python\Python312\Scripts;C:\Users\fnh3651\AppData\Local\Programs\Python\Python312;C:\Users\fnh3651\AppData\Local\Programs\Python\Python37-32\Scripts;C:\Users\fnh3651\AppData\Local\Programs\Python\Python37-32;C:\Users\fnh3651\AppData\Local\Microsoft\WindowsApps;C:\Users\fnh3651.dotnet\tools;C:\TrueBeam\PyWinAuto_HAL_Dependencies\TDSConfigManager;

  7. lostmsu commented on May 10, 2024

    @lostmsu
    lostmsu
    on May 10, 2024
    Member
    More actions

    @manju1847 no, sys.path of Python.

  8. manju1847 commented on May 10, 2024

    @manju1847
    manju1847
    on May 10, 2024
    Author
    More actions

    (client_env) C:\Automation\Main\drop_hal_pywinauto\TA_HAL>python --version
    Python 3.10.11

    (client_env) C:\Automation\Main\drop_hal_pywinauto\TA_HAL>where python
    C:\Automation\Main\drop_hal_pywinauto\client_env\Scripts\python.exe
    C:\Users\svc-pa-autbuild\AppData\Local\Programs\Python\Python310\python.exe
    C:\Users\svc-pa-autbuild\AppData\Local\Microsoft\WindowsApps\python.exe

    (client_env) C:\Automation\Main\drop_hal_pywinauto\TA_HAL>python
    Python 3.10.11 (tags/v3.10.11:7d4cc5a, Apr 5 2023, 00:38:17) [MSC v.1929 64 bit (AMD64)] on win32
    Type "help", "copyright", "credits" or "license" for more information.

    import sys
    print(sys.path)
    ['', 'C:\Automation\Main\drop_hal_pywinauto\TA_HAL\"TA_HAL"', 'C:\Users\svc-pa-autbuild\AppData\Local\Programs\Python\Python310\python310.zip', 'C:\Users\svc-pa-autbuild\AppData\Local\Programs\Python\Python310\DLLs', 'C:\Users\svc-pa-autbuild\AppData\Local\Programs\Python\Python310\lib', 'C:\Users\svc-pa-autbuild\AppData\Local\Programs\Python\Python310', 'C:\Automation\Main\drop_hal_pywinauto\client_env', 'C:\Automation\Main\drop_hal_pywinauto\client_env\lib\site-packages', 'C:\Automation\Main\drop_hal_pywinauto\client_env\lib\site-packages\win32', 'C:\Automation\Main\drop_hal_pywinauto\client_env\lib\site-packages\win32\lib', 'C:\Automation\Main\drop_hal_pywinauto\client_env\lib\site-packages\Pythonwin']

  9. lostmsu commented on May 10, 2024

    @lostmsu
    lostmsu
    on May 10, 2024
    Member
    More actions

    The first line seems suspicious. There are quotes in directory name. These are impossible on Windows.

  10. lostmsu
    reopened this on May 10, 2024
  11. lostmsu
    added 6 commits that reference this issue on May 10, 2024

    handle bad paths in sys.path

    This issue will close once commit fe3ca4f is merged into the 'losttech/master' branch.
    fe3ca4f

    handle bad paths in sys.path

    This issue will close once commit 1373cbc is merged into the 'losttech/master' branch.
    1373cbc

    handle bad paths in sys.path

    This issue will close once commit 618e84a is merged into the 'losttech/master' branch.
    618e84a

    handle bad paths in sys.path

    This issue will close once commit 3b2958b is merged into the 'losttech/master' branch.
    3b2958b

    handle bad paths in sys.path

    This issue will close once commit eef9619 is merged into the 'losttech/master' branch.
    eef9619

    handle bad paths in sys.path

    This issue will close once commit eb61851 is merged into the 'losttech/master' branch.
    eb61851
  12. filmor
    closed this as completedin #2383on May 11, 2024
  13. filmor
    added a commit that references this issue on May 11, 2024

    handle bad paths in sys.path (#2383)

    This issue will close once commit b112885 is merged into the 'master' branch.
    b112885
  14. manju1847 commented on May 11, 2024

    @manju1847
    manju1847
    on May 11, 2024
    Author
    More actions

    The first line seems suspicious. There are quotes in directory name. These are impossible on Windows.

    You nailed it!!!! Yes, that is the root cause. After removing quotes from sys.path, AddReference is happy. Thanks a lot for helping to resolve this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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

      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.