У меня есть деамон для предварительной загрузки сборки или запуска новой исполняемой сборки.Как загружать сборки во время выполнения с ядром dotnet
Для предварительной загрузки сборки:
Assembly assembly = Assembly.LoadFile(dllPath);
Для запуска библиотеки DLL:
AppDomain.CurrentDomain.ExecuteAssembly(executablePath, args);
, но я не могу найти LoadFile или AppDomain класс в netcoreapp1.0 API.
Как перенести его для ядра ячеек?
Я попытался использовать LoadFromAssemblyPath и AssemblyLoadContext. , но он делает исключения во время выполнения.
здесь код:
using System;
using System.Runtime.Loader;
using System.Reflection;
using System.IO;
namespace Tizen.DotnetLauncher
{
class Shield
{
public static void Main(string[] args)
{
if (args.Length < 1) return;
var asl = new AssemblyLoader();
string fpath = Path.GetFullPath(args[0]);
Console.WriteLine(fpath);
var asm = asl.LoadFromAssemblyPath(fpath);
Type[] types = null;
try
{
types = asm.GetTypes();
}
catch (ReflectionTypeLoadException e)
{
foreach (Exception ex in e.LoaderExceptions)
{
Console.WriteLine(ex);
}
}
foreach (Type info in types)
{
Console.WriteLine(info.GetTypeInfo());
}
}
class AssemblyLoader : AssemblyLoadContext
{
protected override Assembly Load(AssemblyName assemblyName)
{
return null;
}
}
}
}
LoaderExceptions выход:
System.IO.FileNotFoundException: Could not load file or assembly 'System.Runtime, Version=4.1.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.
File name: 'System.Runtime, Version=4.1.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' ---> System.IO.FileNotFoundException: Could not load the specified file.
File name: 'System.Runtime'
at System.Runtime.Loader.AssemblyLoadContext.ResolveUsingEvent(AssemblyName assemblyName)
at System.Runtime.Loader.AssemblyLoadContext.ResolveUsingResolvingEvent(IntPtr gchManagedAssemblyLoadContext, AssemblyName assemblyName)
исключения
Возможный дубликат [Как загрузить сборки, расположенные в папке в консольном приложении .net) (http://stackoverflow.com/questions/37895278/how-to-load-assemblies-located-in-a-folder -in-net-core-console-app) – Mat