Update Bootstrap.cs

pull/1/head
Ogoun 5 years ago
parent be3ccca524
commit 7f0d63cf2b

@ -96,31 +96,47 @@ namespace ZeroLevel
{ {
try try
{ {
Log.Info($"[Bootstrap] Resolve assembly '{args.Name}'"); Log.Info($"[Bootstrap] Resolve assembly '{args.Name}' {args.Name}");
if (args.Name.StartsWith("Newtonsoft.Json", StringComparison.Ordinal)) if (args.Name.StartsWith("Newtonsoft.Json", StringComparison.Ordinal))
{ {
return Assembly.LoadFile(Path.Combine(Configuration.BaseDirectory, "Newtonsoft.Json.dll")); return Assembly.LoadFile(Path.Combine(Configuration.BaseDirectory, "Newtonsoft.Json.dll"));
} }
var candidates = Directory.GetFiles(Path.Combine(Configuration.BaseDirectory), "*.dll", SearchOption.TopDirectoryOnly)?.ToList(); string name = args.Name.Split(',')[0];
if (candidates != null && candidates.Any()) if (name.EndsWith(".resources")) return null;
foreach (string file in Directory.
GetFiles(Path.Combine(Configuration.BaseDirectory), "*.dll", SearchOption.TopDirectoryOnly))
{ {
int max = -1; int index = -1; if (file.IndexOf(name, StringComparison.OrdinalIgnoreCase) >= 0)
for (int i = 0; i < candidates.Count; i++)
{
if (args.Name.IndexOf(candidates[i]) >= 0)
{
if (max < candidates[i].Length)
{
max = candidates[i].Length;
index = i;
}
}
}
if (index != -1)
{ {
return Assembly.LoadFile(candidates[index]); Log.Info($"[Bootstrap] Resolve assembly '{args.Name}' found '{file}'");
return Assembly.LoadFile(file);
} }
} }
//var candidates = Directory.GetFiles(Path.Combine(Configuration.BaseDirectory), name + ".dll", SearchOption.TopDirectoryOnly)
// ?.Select(s => Path.GetFileNameWithoutExtension(s))
// ?.ToList();
//if (candidates != null && candidates.Any())
//{
// int max = -1; int index = -1;
// for (int i = 0; i < candidates.Count; i++)
// {
// if (args.Name.IndexOf(candidates[i], StringComparison.OrdinalIgnoreCase) >= 0)
// {
// if (max < candidates[i].Length)
// {
// max = candidates[i].Length;
// index = i;
// }
// }
// }
// if (index != -1)
// {
// return Assembly.LoadFile(Path.Combine(Configuration.BaseDirectory, candidates[index] + ".dll"));
// }
//}
} }
catch (Exception ex) catch (Exception ex)
{ {

Loading…
Cancel
Save

Powered by TurnKey Linux.