我想检索一个包含应用程序包中所有Assemblies
的列表,以便动态加载它们。
我正在尝试使用此代码:
public static IEnumerable<Assembly> AssembliesInAppFolder
{
get
{
var entryAssembly = Assembly.GetExecutingAssembly();
var path = entryAssembly.Location;
var folder = Path.GetDirectoryName(path);
var assemblies = new Collection<Assembly>();
var fileNames = FilterFiles(folder, ".dll", ".exe");
foreach (var fileName in fileNames)
{
try
{
assemblies.Add(Assembly.LoadFile(fileName));
}
catch (FileNotFoundException)
{
}
catch (FileLoadException)
{
}
catch (BadImageFormatException)
{
}
}
return assemblies;
}
}
public static IEnumerable<string> FilterFiles(string path, params string[] extensionsWithNoWildcard)
{
return
Directory
.EnumerateFiles(path, "*.*")
.Where(file => extensionsWithNoWildcard.Any(x => file.EndsWith(x, StringComparison.OrdinalIgnoreCase)));
}
但它在Android中不起作用(在发布模式下,它会在Directory.EnumerateFiles(path, "*.*")
处抛出 - 其中path是一个空字符串,说明:
&#34; System.ArgumentException:指定的路径不是合法形式(空)。&#34;