0

I have a method that performs a search in both the local assembly and in the current directory. It is looking for a class based on the name provided (reflection). However I now want to only load the classes/dlls that I am looking for into memory as opposed to loading them all and selecting the one that I want from it. I have been told that marshalbyrefobject could be used to do this. [Below is the code I am currently using]

The solution would be to create 2 app domains and have one load all the assembiles and do the checks then unload on of the app domains, though im not sure how to go about doing that.

4

1 回答 1

0

据我所知,您可以通过使用Assembly类事先查询它们来避免加载程序集。

完整的工作模型如下所示:

1 -通过 Assembly 类收集信息

装配文件:

Assembly assembly = Assembly.ReflectionOnlyLoadFrom(fileName);

本地组装:

Assembly myAssembly = Assembly.GetExecutingAssembly();

2 -遍历每个 Assembly 引用中存在的类

Assembly mscorlib = typeof(string).Assembly;

foreach (Type type in mscorlib.GetTypes())
{
    Console.WriteLine(type.FullName);
}

3 - 选择要使用的程序集后,将其加载到您的应用程序域中

Assembly assembly = Assembly.Load(fullAssemblyName);

或者

Assembly assembly = Assembly.LoadFrom(fileName);

从以下帖子中复制的示例,因此,如果您认为它们有助于解决您的问题,请随时支持那里的回复!

C#:列出程序集中的所有类

于 2013-12-06T14:34:38.073 回答