Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb65fa30

Browse files
committed
Use Assembly.Load(Byte[]) instead of Assembly.LoadFrom.
1 parentdfdcfe7 commitb65fa30

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

‎pythonnet/src/runtime/assemblymanager.cs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ internal class AssemblyManager {
3030
staticResolveEventHandlerrhandler;
3131
staticDictionary<string,int>probed;
3232
staticList<Assembly>assemblies;
33+
staticDictionary<string,Assembly>loadedAssemblies;
3334
internalstaticList<string>pypath;
3435

3536
privateAssemblyManager(){}
@@ -46,6 +47,7 @@ internal static void Initialize() {
4647
probed=newDictionary<string,int>(32);
4748
//generics = new Dictionary<string, Dictionary<string, string>>();
4849
assemblies=newList<Assembly>(16);
50+
loadedAssemblies=newDictionary<string,Assembly>();
4951
pypath=newList<string>(16);
5052

5153
AppDomaindomain=AppDomain.CurrentDomain;
@@ -202,7 +204,19 @@ public static Assembly LoadAssemblyPath(string name) {
202204
stringpath=FindAssembly(name);
203205
Assemblyassembly=null;
204206
if(path!=null){
205-
try{assembly=Assembly.LoadFrom(path);}
207+
if(loadedAssemblies.ContainsKey(path)){
208+
returnloadedAssemblies[path];
209+
}
210+
// Avoid using Assembly.LoadFrom as referenced assemblies that exist
211+
// in the same path will be loaded directly from there, rather than
212+
// using other versions already loaded. This is a problem if there
213+
// is a Python.Runtime.dll in the same folder as the assembly being
214+
// loaded, as that will result in two instances being loaded.
215+
try{
216+
byte[]bytes=System.IO.File.ReadAllBytes(path);
217+
assembly=Assembly.Load(bytes);
218+
loadedAssemblies[path]=assembly;
219+
}
206220
catch{}
207221
}
208222
returnassembly;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp