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 8462875
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T14:17:53+00:00 2026-06-10T14:17:53+00:00

I am trying to implement a plugin system in C#, and for that I

  • 0

I am trying to implement a plugin system in C#, and for that I created the following classes and interfaces:

Included in both loader and plugin:

interface IDevicePlugin {
    string GetName();
    string GetVersion();
}

Plugin code (compiles to .dll)

public class DummyPlugin : IDevicePlugin {
        protected string name;
        protected string version;

        public string GetName() {
            return name;
        }
        public string GetVersion() {
            return version;
        }
  }

The code to load the plugin is as follows:

IDevicePlugin thePlugin;
Assembly plugin = Assembly.LoadFrom("plugin.dll");

foreach (Type pluginType in plugin.GetTypes()) {
       if (pluginType.IsPublic && !pluginType.IsAbstract) {
            Type typeInterface = pluginType.GetInterface("IDevicePlugin", true);
            if (typeInterface != null) {
                 // the plugin implements our IDevicePlugin interface
                 thePlugin =  (IDevicePlugin)Activator.
                         CreateInstance(plugin.GetType(pluginType.ToString()));
            }
       }
}

And this crashes with:

Unable to cast object of type 'PluginTest.DummyPlugin' to type 'PluginTest.IDevicePlugin'.
  • 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-10T14:17:55+00:00Added an answer on June 10, 2026 at 2:17 pm

    The interface exists twice:
    Once in your plugin.dll and once in your loader.
    The reason is that you added a reference (=link) to the *.cs file containing the interface definition to the plugin project. Additionally, the same *.cs file is part of the loader project.
    Because of that, the interface gets compiled into both assemblies. These are two different interfaces, even when they are named the same!

    To fix this problem, you should do the following:

    Either add a reference for the Loader project to the plugin project
    – OR –
    Create a new project for the interface and reference this project from both the loader and the plugin projects.

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

Sidebar

Related Questions

I was trying to implement https on a subdomain. I have included SSL_requriment plugin
I am trying to implement the TinyMCE Spellcheck plugin that uses GoogleSpell. The thing
I am trying to implement a nagios plugin, and doing so requires that I
I am trying to develop a plugin system, which provides a interface to load
I am trying to implement this plugin Phonegap system notification . I am reading
I'm trying to implement the jQuery Address plugin in my project. I'm following the
I'm trying to implement a simple plugin system which will allow people to write
I am trying to implement this plugin Phonegap system notification . I am calling
I'm trying to implement a plugin system, but I'm having some problems. In the
I am trying to implement a search plugin that I found into an application

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.