Repository navigation
fix: load .NET assemblies when running on .NET 9+ - #174
Merged
Merged
Conversation
GitHub-hosted runners now ship .NET 8, 9 and 10. clr_loader 0.2.x (used
with pythonnet 3.0.x, e.g. on Python 3.9) picks the runtime by string
sort, so it selects .NET 9. On .NET 9+, pythonnet 3.0.x's
clr.AddReference("<abs path>.dll") parses the path as an assembly name
and throws FileNotFoundException before its full-path fallback runs. The
error was swallowed, so imports failed with
"No module named 'Microsoft.Azure'".
Pass the path without the ".dll" suffix so pythonnet probes and loads
"<path>.dll" directly, which works on .NET 8, 9 and 10 with pythonnet
3.0.x and 3.1.x.
Also pin the e2e matrix to Python 3.13 instead of '3.x', which now
resolves to 3.14 and is outside requires-python (<3.14).
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
arjenkroezen-msft
force-pushed
the
fix/dotnet9-assembly-loading
branch
from
September 24, 2026 08:16
2835298 to
87bf48c
Compare
Yennifer Santos (ydaponte)
approved these changes
Sep 24, 2026
Yennifer Santos (ydaponte)
left a comment
Collaborator
There was a problem hiding this comment.
LGTM!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes the
ci / buildfailure seen on everyCI/CDPR run since January 2026 (including #173, #167, #168 and #171).Root cause
GitHub-hosted runners now have .NET 8, 9 and 10 installed.
poetry.lock, and what Python 3.9 installs), runtimes are sorted by version string, so"9.0.x"beats"8.0.x"and"10.0.x". The evaluator therefore runs on .NET 9.clr.AddReference("/abs/path/Foo.dll")in pythonnet 3.0.x parses the path as an assembly name and throwsFileNotFoundExceptionbefore its full-path fallback runs.load_dotnet_assemblies()swallows that exception, so the tests fail later withModuleNotFoundError: No module named 'Microsoft.Azure'.This affects users too, not just CI: anyone on Python 3.9 (or with pythonnet 3.0.x pinned) who has .NET 9 installed next to .NET 8 hits the same error.
Changes
_pythonnet/__init__.py: pass the assembly path without the.dllsuffix. pythonnet then probes and loads<path>.dlldirectly, which works on .NET 8, 9 and 10 with pythonnet 3.0.x and 3.1.x.ci.yml: pin the e2e matrix to3.13instead of3.x.3.xnow resolves to Python 3.14, whichrequires-python = ">=3.9,<3.14"rejects, so the e2e jobs would fail as soon asbuildis green.Validation (local, with .NET 8.0 + 9.0 + 10.0 runtimes installed like the runners)
pre-commit run --all-filesNo module named 'Microsoft.Azure'pytest examplesWindows was not tested locally.
After this merges, #173 (action pinning) should go green on a rebase / re-run. It touches different lines of
ci.yml, so there's no conflict.