Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0ac66b3

Browse files
committed
Merge pull request #38 from tonyroberts/develop
embed Python.Runtime.dll in nPython fixes #26
2 parents d97616d + f630a5a commit 0ac66b3

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

pythonnet/src/console/Console.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,9 @@
192192
</ItemGroup>
193193
<ItemGroup>
194194
<Content Include="python-clear.ico" />
195+
<EmbeddedResource Include="$(PythonBuildDir)\Python.Runtime.dll">
196+
<LogicalName>Python.Runtime.dll</LogicalName>
197+
</EmbeddedResource>
195198
</ItemGroup>
196199
<ItemGroup>
197200
<None Include="app.config" />

pythonnet/src/console/pythonconsole.cs

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
// ==========================================================================
99

1010
using System;
11+
using System.Reflection;
1112
using Python.Runtime;
1213

1314
namespace Python.Runtime {
@@ -27,6 +28,30 @@ public static int Main(string[] args) {
2728
return i;
2829
}
2930

30-
}
31+
// Register a callback function to load embedded assmeblies.
32+
// (Python.Runtime.dll is included as a resource)
33+
private sealed class AssemblyLoader {
34+
public AssemblyLoader() {
35+
AppDomain.CurrentDomain.AssemblyResolve += (sender, args) => {
36+
String resourceName = new AssemblyName(args.Name).Name + ".dll";
37+
38+
// looks for the assembly from the resources and load it
39+
using (var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName)) {
40+
if (stream != null) {
41+
Byte[] assemblyData = new Byte[stream.Length];
42+
stream.Read(assemblyData, 0, assemblyData.Length);
43+
return Assembly.Load(assemblyData);
44+
}
45+
}
46+
47+
return null;
48+
};
49+
}
50+
};
51+
52+
private static AssemblyLoader assemblyLoader = new AssemblyLoader();
53+
54+
};
55+
3156

3257
}

0 commit comments

Comments
 (0)