Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8722697
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T07:28:14+00:00 2026-06-13T07:28:14+00:00

I am building a windows service based on plugin architecture and I run into

  • 0

I am building a windows service based on plugin architecture and I run into some problem.
The problem is I want plugin to fire event on the main application. Here is some code.

These are delegates

namespace eTreasury.SchedulerInterface
{
    public enum Severity
    {
        Message,
        Warning,
        Error
    }

    public delegate void ErrorHandler(string message, Severity errorSeverity);
    public delegate void CompletedHandler(string message);
    public delegate void ProgressReportHandler(string message, int percentCompleted);
}

This is interface

public interface IPluginInterface : IDisposable
    {
        string Identifier{ get; }

        void Run();
        void Dispose();

        event ErrorHandler OnError;
        event CompletedHandler OnCompleted;
        event ProgressReportHandler OnProgress;
    }

This is base class I want all plugins to inherit from

public abstract class BasePlugin : MarshalByRefObject, IPluginInterface
{
    protected string _identifier;
    public string Identifier
    {
        get { return _identifier; }
    }

    public abstract void Run();

    protected void ReportError(string message, Severity errorSeverity)
    {
        if (OnError != null)
            OnError(message, errorSeverity);
    }
    protected void ReportProgress(string message, int percentCompleted)
    {
        if (OnProgress != null)
            OnProgress(message, percentCompleted);
    }
    protected void ReportProgress(string message)
    {
        ReportProgress(message, 0);
    }
    protected void ReportCompleted(string message)
    {
        if (OnCompleted != null)
            OnCompleted(message);
    }

    public void Dispose()
    {
        OnError = null;
        OnCompleted = null;
        OnProgress = null;
        _identifier = null;
    }

    public event ErrorHandler OnError;
    public event CompletedHandler OnCompleted;
    public event ProgressReportHandler OnProgress;
}

This is plugin

public class CurrencyRatesPlugin : BasePlugin
{
    public CurrencyRatesPlugin()
    {
        _identifier = "CurrencyRatesPlugin";
    }

    public override void Run()
    {
        try
        {
           ReportProgress("bla", 0);
        }
        catch (Exception e)
        {
            ReportError("bla");
        }
    }
}

And this is my windows service code

public partial class CurrencyRatesPluginService : ServiceBase
    {
        AppDomain appDomain;
        IPluginInterface pluginInterface;
        System.Timers.Timer Timer = null;

        public CurrencyRatesPluginService()
        {
            InitializeComponent();
        }

        protected override void OnStart(string[] args)
        {
           try
            {
                this.appDomain = CreateAppDomain();
                this.pluginInterface = (IPluginInterface)appDomain.CreateInstanceFrom("C:\\eTreasuryScheduler\\Plugins\\eTreasury.CurrencyRatesPlugin.dll", "eTreasury.Plugins.CurrencyRatesPlugin.CurrencyRatesPlugin").Unwrap();

                PluginSection section = (PluginSection)ConfigurationManager.GetSection("PluginSectionGroup/PluginSection");
                if (section == null)
                {
                    EventLogManager.LogError("bla");
                }
                else
                {
                    Timer = new System.Timers.Timer();
                    Timer.Enabled = false;
                    Timer.Interval = section.PluginItems[0].Interval;
                    Timer.Elapsed += new System.Timers.ElapsedEventHandler(Timer_Elapsed);
                    Timer.Start();
                }
            }
            catch(Exception ex)
            {
                EventLogManager.LogError(String.Format("{0}...{1}", ex.Message, ex.InnerException == null ? string.Empty : ex.InnerException.Message));
            }
        }

        protected override void OnStop()
        {
            Timer.Stop();
            this.pluginInterface.Dispose();
            AppDomain.Unload(this.appDomain);
        }

        void Timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
        {
            Process();
        }

        void Process()
        {
            try
            {
                this.pluginInterface.OnProgress += ProcessProgressReportHandler;
                this.pluginInterface.OnCompleted += ProcessCompletedHandler;

                pluginInterface.Run();

                this.pluginInterface.OnProgress -= ProcessProgressReportHandler;
                this.pluginInterface.OnCompleted -= ProcessCompletedHandler;
            }
            catch (Exception ex)
            {
                EventLogManager.LogError(String.Format("{0}...{1}", ex.Message, ex.InnerException == null ? string.Empty : ex.InnerException.Message));
            }
        }

        private void ProcessProgressReportHandler(string message, int percentCompleted)
        {
            EventLogManager.LogInformation(message);
        }

        private void ProcessCompletedHandler(string message)
        {
            EventLogManager.LogInformation(message);
        }

        AppDomain CreateAppDomain()
        {
            ...
        }
    }

And everythig is working fine except the events.
The error occurs here

this.pluginInterface.OnProgress += ProcessProgressReportHandler;

And the error message is

Exception has been thrown by the target of an invocation....Could not load file or assembly 'eTreasury.SchedulerService, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T07:28:15+00:00Added an answer on June 13, 2026 at 7:28 am

    I`ve added IHost interface and Initialize methods in plugin interface. When loading plugin in host application I call Initialize method of that plugin and pass Host to it. After this I have ability to call host methods from plugin.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We're building an application designed to run on Windows-based servers. One of the considerations
I am building a Windows forms application using VS2010. I want to read the
I am well into building a Core Data tab-based iPad application. I am passing
I'm building a windows service application which has a configuration to compile it as
I'm building a multi-threaded windows service application in Delphi XE2 which uses ADO database
I'm in the middle of building a simple windows service and I'm running into
I am building a Windows Service that will audit users based on a schedule
I've ran into a really weird problem. I am building a heavily distributed application
I wanted a windows service I'm building to run overnight. So I changed my
I am building a web/mobile social service application for Windows Phone. As a final

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.