我正在为我需要加载程序集并在不同的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();
}
}
可能是什么问题? 任何人都可以帮助我!
它不工作太...... – Srivastava 2010-11-20 09:46:47
每次你在你的代码中使用它时,你都需要提供'IMFDBAnalyserPlugin' *的全限定引用,除非你选择在代码文件的顶部。我用完整的语法更新了我的文章。 – 2010-11-20 09:51:15