Skip to content

get_coreclr exception on Windows 32 bit #14

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
DareDevilDenis opened this issue Oct 27, 2021 · 5 comments
Closed

get_coreclr exception on Windows 32 bit #14

DareDevilDenis opened this issue Oct 27, 2021 · 5 comments

Comments

@DareDevilDenis
Copy link
Contributor

Using clr-loader 0.1.6 with pythonnet 3.0.0.dev1.

When running on 32 bit Windows, when my code calls:

config_path = get_coreclr(r'C:\MyApp.runtimeconfig.json')

It throws exception:

Traceback (most recent call last):
  File "MyApp.py", line 10, in <module>
    config_path = get_coreclr(r'C:\MyApp.runtimeconfig.json')
  File "C:\Program Files\Python38-32\lib\site-packages\clr_loader\__init__.py", line 38, in get_coreclr
    dotnet_root = find_dotnet_root()
  File "C:\Program Files\Python38-32\lib\site-packages\clr_loader\util\find.py", line 19, in find_dotnet_root
    dotnet_root = os.path.join(prog_files, "dotnet")
  File "C:\Program Files\Python38-32\lib\ntpath.py", line 78, in join
    path = os.fspath(path)
TypeError: expected str, bytes or os.PathLike object, not NoneType

This is because clr_loader/util/find.py tries to read environment variable "ProgramFiles(x86)" but it doesn't exist on 32 bit Windows:

def find_dotnet_root() -> str:
    dotnet_root = os.environ.get("DOTNET_ROOT", None)
    if dotnet_root is not None:
        return dotnet_root

    if sys.platform == "win32":
        # On Windows, the host library is stored separately from dotnet.exe for x86
        if sys.maxsize > 2 ** 32:
            prog_files = os.environ.get("ProgramFiles")
        else:
            prog_files = os.environ.get("ProgramFiles(x86)")    <--- doesn't exist on 32 bit Windows

        dotnet_root = os.path.join(prog_files, "dotnet")   <--- exception
@filmor
Copy link
Member

filmor commented Oct 27, 2021

Could you test whether replacing the given erroring line by

prog_files = os.environ.get("ProgramFiles(x86)") or os.environ.get("ProgramFiles(x86)")

works and create a PR if it does? I don't have a system to test this with, the code is relevant for 32bit processes on 64bit Windows systems.

@DareDevilDenis
Copy link
Contributor Author

Do you mean:
prog_files = os.environ.get("ProgramFiles(x86)") or os.environ.get("ProgramFiles")

Actually, instead of this checking of sys.maxsize and os.environ, why not just simply have:

if sys.platform == "win32":
        prog_files = os.environ.get("ProgramFiles")

This returns:

  • On 32 bit Windows: C:\Program Files
  • On 64 bit Windows, 32 bit Python: C:\Program Files (x86)
  • On 64 bit Windows, 64 bit Python: C:\Program Files

Isn't that what you want?

@DareDevilDenis
Copy link
Contributor Author

I submitted pull request: #15 with the change that I suggested above.
I tested this on:

  • 32 bit Windows: C:\Program Files
  • 64 bit Windows, 32 bit Python: C:\Program Files (x86)
  • 64 bit Windows, 64 bit Python

@DareDevilDenis
Copy link
Contributor Author

Hi @filmor. Does the PR look ok? It's my first one on github so I hope that I did it right!

@DareDevilDenis
Copy link
Contributor Author

Thanks for approving and merging the PR. Closing this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants