【发布时间】:2011-05-13 00:49:46
【问题描述】:
我正在开发一个桌面应用程序,我需要为其加载程序集并在不同的 appdomain 中执行它。
为了加载我写的程序集:
public static DataTable GetAllPluginNames(string[] args)
{
SqlConnection sConnection = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]);
//ToDo: create a table of one column - only name of the plugin and return that.
//ToDo: refer the code from MFAssemblyValidator from MFPluggerService.
DataTable dt = null;
List<string> assemblyNames = new List<string>();
Assembly[] oAssemblies = new Assembly[args.Length];
for (int assemblyCount = 0; assemblyCount < args.Length; assemblyCount++)
{
oAssemblies[assemblyCount] = Assembly.LoadFile(args[assemblyCount]);
try
{
foreach (Type oType in oAssemblies[assemblyCount].GetTypes())
{
// Check whether class is inheriting from IMFDBAnalyserPlugin.
if (oType.GetInterface("IMFDBAnalyserPlugin") == typeof(IMFDBAnalyserPlugin))
{
assemblyNames.Add(args[assemblyCount].Substring(args[assemblyCount].LastIndexOf("\\") + 1));
}
}
return dt;
}
catch (Exception ex)
{
lblError.Text = "ERROR";
}
// Passing data one application domain to another.
AppDomain.CurrentDomain.SetData("AssemblyNames", assemblyNames.ToArray());
}
}
但typeof(IMFDBAnalyserPlugin)) 显示命名空间错误。
IMFDBAnalyserPlugin 是我程序中的接口类:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace MFDBAnalyser
{
public interface IMFDBAnalyserPlugin
{
void ExecutePlugin();
}
}
可能是什么问题? 谁能帮帮我!!
【问题讨论】:
标签: c# visual-studio namespaces