Skip to content

Commit cf0ce2e

Browse files
Metadoriusfilmor
authored andcommitted
Support .NET Framework 4.6.1
1 parent 39c575e commit cf0ce2e

6 files changed

Lines changed: 41 additions & 3 deletions

File tree

AUTHORS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,3 +89,4 @@
8989
- Ehsan Iran-Nejad ([@eirannejad](https://github.com/eirannejad))
9090
- ([@legomanww](https://github.com/legomanww))
9191
- ([@gertdreyer](https://github.com/gertdreyer))
92+
- Kerbiter ([@Metadorius](https://github.com/Metadorius))

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,13 @@ This document follows the conventions laid out in [Keep a CHANGELOG][].
1010
### Added
1111

1212
- Support `del obj[...]` for types derived from `IList<T>` and `IDictionary<K, V>`
13+
- Support for .NET Framework 4.6.1 (#2701)
1314

1415
### Changed
1516
### Fixed
1617

1718
- Fixed crash when trying to `del clrObj[...]` for non-arrays
18-
- ci: properly exclude job (#2542)
19+
- ci: properly exclude job (#2542)
1920

2021
## [3.0.5](https://github.com/pythonnet/pythonnet/releases/tag/v3.0.5) - 2024-12-13
2122

doc/source/python.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ Mono (``mono``)
4545

4646
.NET Framework (``netfx``)
4747
Default on Windows and also only supported there. Must be at least version
48-
4.7.2.
48+
4.6.1, with 4.7.2 or later recommended.
4949

5050
.NET Core (``coreclr``)
5151
Self-contained is not supported, must be at least version 3.1.

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ def finalize_options(self):
127127
dotnet_libs = [
128128
DotnetLib(
129129
"python-runtime",
130-
"src/runtime/Python.Runtime.csproj",
130+
"src/compat/Python.Runtime.Compat.csproj",
131131
output="pythonnet/runtime",
132132
)
133133
]
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!-- A dummy project to force MSBuild to package .NET 4.6.1 requirements -->
2+
<Project Sdk="Microsoft.NET.Sdk">
3+
<PropertyGroup>
4+
<TargetFramework>net461</TargetFramework>
5+
<OutputType>Library</OutputType>
6+
<!-- Don't copy the dummy assembly/pdb to output; we only need the resolved references -->
7+
<CopyBuildOutputToOutputDirectory>false</CopyBuildOutputToOutputDirectory>
8+
<CopyOutputSymbolsToOutputDirectory>false</CopyOutputSymbolsToOutputDirectory>
9+
</PropertyGroup>
10+
<ItemGroup>
11+
<ProjectReference Include="..\runtime\Python.Runtime.csproj" />
12+
</ItemGroup>
13+
</Project>

src/runtime/Loader.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.IO;
23
using System.Text;
34

45
namespace Python.Runtime
@@ -12,6 +13,28 @@ public unsafe static int Initialize(IntPtr data, int size)
1213
{
1314
try
1415
{
16+
// On .NET Framework, the host is python.exe which has no binding
17+
// redirects for netstandard2.0 shims (e.g. RuntimeInformation
18+
// Version=0.0.0.0 vs the 4.0.2.0 shim on disk). Binding redirects
19+
// via config files can't be injected after AppDomain creation, so
20+
// resolve assemblies from our runtime directory directly.
21+
// Only needed on .NET Framework; on .NET (Core) this causes
22+
// duplicate assembly loads, as .deps.json is respected and
23+
// the correct assembly is already found.
24+
if (typeof(object).Assembly.GetName().Name == "mscorlib")
25+
{
26+
AppDomain.CurrentDomain.AssemblyResolve += (_, args) =>
27+
{
28+
var name = new System.Reflection.AssemblyName(args.Name);
29+
var dir = Path.GetDirectoryName(typeof(Loader).Assembly.Location);
30+
var path = Path.Combine(dir, name.Name + ".dll");
31+
32+
return File.Exists(path)
33+
? System.Reflection.Assembly.LoadFrom(path)
34+
: null;
35+
};
36+
}
37+
1538
var dllPath = Encodings.UTF8.GetString((byte*)data.ToPointer(), size);
1639

1740
if (!string.IsNullOrEmpty(dllPath))

0 commit comments

Comments
 (0)