PrintException(e);
}
- public static bool Initialize(string preloadDirectory)
+ public static bool Initialize(string preloadFile)
{
try
{
{
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);
+ }
+ }
}
}
}