我正在爲我需要加載程序集並在不同的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