mirror of
https://github.com/Bubuni-Team/telegram-bot.git
synced 2026-07-31 00:29:24 +03:00
Support module dependencies from non-app directory
This commit is contained in:
+19
-4
@@ -164,14 +164,29 @@ namespace Kruzya.TelegramBot.Core
|
|||||||
|
|
||||||
appDomain.AssemblyResolve += delegate(object? sender, ResolveEventArgs args)
|
appDomain.AssemblyResolve += delegate(object? sender, ResolveEventArgs args)
|
||||||
{
|
{
|
||||||
var basePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
|
var assemblyName = new AssemblyName(args.Name).Name + ".dll";
|
||||||
var assemblyPath = Path.Combine(basePath, new AssemblyName(args.Name).Name + ".dll");
|
|
||||||
if (!File.Exists(assemblyPath))
|
var possiblePaths = new List<string>();
|
||||||
|
if (args.RequestingAssembly != null)
|
||||||
{
|
{
|
||||||
return null;
|
var modulePath = Path.GetDirectoryName(args.RequestingAssembly.Location);
|
||||||
|
possiblePaths.Add(modulePath);
|
||||||
|
possiblePaths.Add(args.RequestingAssembly.Location.Replace(".dll", ""));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
possiblePaths.Add(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location));
|
||||||
|
possiblePaths.Add(Environment.CurrentDirectory);
|
||||||
|
|
||||||
|
foreach (var basePath in possiblePaths)
|
||||||
|
{
|
||||||
|
var assemblyPath = $"{basePath}/{assemblyName}";
|
||||||
|
if (File.Exists(assemblyPath))
|
||||||
|
{
|
||||||
return Assembly.LoadFrom(assemblyPath);
|
return Assembly.LoadFrom(assemblyPath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user