From af016aa0f9cf9e442f0d122d933875c54e258a77 Mon Sep 17 00:00:00 2001 From: "pius.lee" Date: Thu, 24 Nov 2016 11:16:25 +0900 Subject: [PATCH] Fix Preload DLL Use LoadFromNativeImagePath for ni dlls. Change directory to text file for reading dll lists. Change-Id: Icc2142a80765e4551ef6b85bdb1e1643f5c9404d --- NativeLauncher/installer-plugin/common.cc | 6 --- .../Tizen.Runtime.Coreclr/AssemblyManager.cs | 52 +++++++++++++++++----- 2 files changed, 41 insertions(+), 17 deletions(-) diff --git a/NativeLauncher/installer-plugin/common.cc b/NativeLauncher/installer-plugin/common.cc index 8701b2e..d4d007f 100644 --- a/NativeLauncher/installer-plugin/common.cc +++ b/NativeLauncher/installer-plugin/common.cc @@ -105,12 +105,6 @@ static void smack_(const char* dll_path) dll_path, nullptr }; - for (const char* arg : args) - { - printf("%s ", arg); - } - printf("\n"); - execv(CHKSMACK, const_cast(args)); exit(0); diff --git a/Tizen.Runtime/Tizen.Runtime.Coreclr/AssemblyManager.cs b/Tizen.Runtime/Tizen.Runtime.Coreclr/AssemblyManager.cs index 26b8868..52297a1 100644 --- a/Tizen.Runtime/Tizen.Runtime.Coreclr/AssemblyManager.cs +++ b/Tizen.Runtime/Tizen.Runtime.Coreclr/AssemblyManager.cs @@ -105,7 +105,7 @@ namespace Tizen.Runtime.Coreclr PrintException(e); } - public static bool Initialize(string preloadDirectory) + public static bool Initialize(string preloadFile) { try { @@ -132,19 +132,49 @@ namespace Tizen.Runtime.Coreclr { CurrentAssemblyLoaderContext = new AssemblyLoader(); - if (!string.IsNullOrEmpty(preloadDirectory)) + if (!string.IsNullOrEmpty(preloadFile)) { - ALog.Debug($"Load from [{preloadDirectory}]"); - DirectoryInfo d = new DirectoryInfo(preloadDirectory); - if (Directory.Exists(d.FullName)) + ALog.Debug($"Load from [{preloadFile}]"); + FileInfo f = new FileInfo(preloadFile); + if (File.Exists(f.FullName)) { - CurrentAssemblyLoaderContext.AddSearchableDirectory(d.FullName); - string[] dlls = Directory.GetFiles(d.FullName, "*.dll"); - - foreach (string dll in dlls) + using (StreamReader sr = File.OpenText(f.FullName)) { - ALog.Debug($"preload dll : {dll}"); - CurrentAssemblyLoaderContext.LoadFromAssemblyPath(dll); + string s = String.Empty; + while ((s = sr.ReadLine()) != null) + { + ALog.Debug($"preload dll : {s}"); + try + { + Assembly asm = null; + if (s.EndsWith(".ni.dll", StringComparison.CurrentCultureIgnoreCase)) + { + asm = CurrentAssemblyLoaderContext.LoadFromNativeImagePath(s, null); + } + else + { + asm = CurrentAssemblyLoaderContext.LoadFromAssemblyPath(s); + } + + // this works strange, vm can't load types except loaded in here. + // so user code spit out not found exception. + /* + if (asm != null) + { + foreach (TypeInfo t in asm.DefinedTypes) + { + ALog.Debug("===> TYPE : " + t.FullName); + GC.KeepAlive(t.AsType()); + } + } + */ + } + catch (Exception e) + { + ALog.Debug("Exception on preload"); + PrintException(e); + } + } } } } -- 2.7.4