Skip to content

merge changes to get npython working again on windows #41

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

Merged
merged 5 commits into from
Apr 11, 2014
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Use Assembly.Load(Byte[]) instead of Assembly.LoadFrom.
  • Loading branch information
tonyroberts committed Apr 11, 2014
commit b65fa30c7b21cce263ed9ada982bd47bc18eea04
16 changes: 15 additions & 1 deletion pythonnet/src/runtime/assemblymanager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ internal class AssemblyManager {
static ResolveEventHandler rhandler;
static Dictionary<string, int> probed;
static List<Assembly> assemblies;
static Dictionary<string, Assembly> loadedAssemblies;
internal static List<string> pypath;

private AssemblyManager() {}
Expand All @@ -46,6 +47,7 @@ internal static void Initialize() {
probed = new Dictionary<string, int>(32);
//generics = new Dictionary<string, Dictionary<string, string>>();
assemblies = new List<Assembly>(16);
loadedAssemblies = new Dictionary<string, Assembly>();
pypath = new List<string>(16);

AppDomain domain = AppDomain.CurrentDomain;
Expand Down Expand Up @@ -202,7 +204,19 @@ public static Assembly LoadAssemblyPath(string name) {
string path = FindAssembly(name);
Assembly assembly = null;
if (path != null) {
try { assembly = Assembly.LoadFrom(path); }
if (loadedAssemblies.ContainsKey(path)) {
return loadedAssemblies[path];
}
// Avoid using Assembly.LoadFrom as referenced assemblies that exist
// in the same path will be loaded directly from there, rather than
// using other versions already loaded. This is a problem if there
// is a Python.Runtime.dll in the same folder as the assembly being
// loaded, as that will result in two instances being loaded.
try {
byte[] bytes = System.IO.File.ReadAllBytes(path);
assembly = Assembly.Load(bytes);
loadedAssemblies[path] = assembly;
}
catch {}
}
return assembly;
Expand Down