I am working on a desktop application for which I need to load the assembly and execute it in different appdomain.
For loading the assembly I have written as:
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());
}
}
but typeof(IMFDBAnalyserPlugin)) is showing a namespace error.
IMFDBAnalyserPlugin is the interface class in my program as:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace MFDBAnalyser
{
public interface IMFDBAnalyserPlugin
{
void ExecutePlugin();
}
}
What might be the problem??
Can anyone help me out!!
Is the
GetAllPluginNamesmethod located under the same namespace as the interfaceIMFDBAnalyserPlugin?If not, you either need to add a
usingdirective to the top of the code file that contains theGetAllPluginNamesmethod, or fully qualify the interface reference with its namespace, i.e.