Reputation: 3578
In my desktop application, I am facing a problem in using the function in Interface class.
I have a function like this for executing plugin
public static string ExecutePugin(string PluginName, string ConnectionString)
{
//ToDo: Get the plugin dll in the memory in a different appdomain. call RunAnalysis method of that
//ToDo: shift the primary key checking method to inside the plugin and return the result back.
//Loads the IMFDBAnalyserPlugin.exe to the current application domain.
AppDomain.CurrentDomain.Load("IMFDBAnalyserPlugin");
// Load the plugin's assembly to the current application doamin.
Assembly oAssembly = AppDomain.CurrentDomain.Load(PluginName);
// This block of code will execute the plugin's assembly code.
foreach (Type oType in oAssembly.GetTypes())
{
if (oType.GetInterface("IMFDBAnalyserPlugin") != null)
{
object oPlugin = Activator.CreateInstance(oType, null, null);
((MFDBAnalyser.IMFDBAnalyserPlugin)oPlugin).ExecutePlugin();
}
}
return string.Empty;
}
where IMFDBAnalyserPlugin class is an interface and contains code like this
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace MFDBAnalyser
{
public class IMFDBAnalyserPlugin
{
void ExecutePlugin();
}
}
but on building the project I am getting the error in MFDBAnalyser.IMFDBAnalyserPlugin as
Error 1 The type name 'IMFDBAnalyserPlugin' does not exist in the type 'MFDBAnalyser.MFDBAnalyser' D:\Projects\Mindfire\GoalPlan\MFDBAnalyser\MFDBAnalyser\PluginManager.cs 57 107 MFDBAnalyser
can anyone help me
Upvotes: 0
Views: 154
Reputation: 43503
namespace MFDBAnalyser
{
interface IMFDBAnalyserPlugin
{
void ExecutePlugin();
}
}
Otherwise oType.GetInterface("IMFDBAnalyserPlugin")
will be always null because there is no such interface there.
Upvotes: 1
Reputation: 166326
Are you including MFDBAnalyser
in the usings in the main class?
Something like
using MFDBAnalyser;
in PluginManager
?
Also,
you should change
public class IMFDBAnalyserPlugin
{
void ExecutePlugin();
}
to
public interface IMFDBAnalyserPlugin
{
void ExecutePlugin();
}
Have a look at interface (C# Reference)
Upvotes: 2