相关疑难解决方法(0)

Visual Studio 8中程序集引用的Aliases属性有何用处

当我在Visual Studio 8中向项目添加程序集引用时,该引用的Aliases属性设置为"global".这个属性有什么用?为什么它设置为全局?

MSDN告诉我,这是程序集的别名列表,但不是为什么我可能想要使用此属性或为什么大多数别名为"全局".

MSDN参考

c# reference csproj visual-studio

66
推荐指数
2
解决办法
4万
查看次数

在不同的AppDomain中加载/卸载程序集

我需要在运行时加载的程序集中执行一个方法.现在我想在方法调用后卸载那些已加载的程序集.我知道我需要一个新的AppDomain,所以我可以卸载库.但在这里,出现了问题.

要加载的程序集是我的插件框架中的插件.他们根本没有切入点.我所知道的是它们包含一些实现给定接口的类型.旧的非AppDomain代码看起来像这样(稍微缩短):

try
{
    string path = Path.GetFullPath("C:\library.dll");
    AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve;
    Assembly asm = Assembly.LoadFrom(path);
    Type[] types = asm.GetExportedTypes();
    foreach (Type t in types)
    {
        if ((t.GetInterface("IStarter") != null) && !t.IsAbstract)
        {
            object tempObj = Activator.CreateInstance(t);
            MethodInfo info = t.GetMethod("GetParameters");
            if (info != null)
            {
                return info.Invoke(tempObj, null) as string;
            }
        }
    }
}
catch (Exception ex)
{
    MessageBox.Show(String.Format("Damn '{0}'.", ex.Message), "Exception", MessageBoxButtons.OK, MessageBoxIcon.Error);
}

private Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
{
    if (args.Name.StartsWith("MyProject.View,"))
    {
        string path = Path.GetFullPath("C:\view.dll"));
        return …
Run Code Online (Sandbox Code Playgroud)

c# reflection mmc appdomain

22
推荐指数
1
解决办法
3万
查看次数

标签 统计

c# ×2

appdomain ×1

csproj ×1

mmc ×1

reference ×1

reflection ×1

visual-studio ×1