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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T03:06:31+00:00 2026-06-16T03:06:31+00:00

Problem – I am trying my hand at plugIn development and all is going

  • 0

Problem – I am trying my hand at plugIn development and all is going well except where trying to cast object A to object B even though A implements B.

Interface:

namespace DynamicApplications
{
    public interface IPlugIn
    {
        string Name { get; set; }
        IPlugInHost myHost { set; }
        void Show();
    }

    public interface IPlugInHost
    {
        bool Register(IPlugIn plug);
    }
}

Class which Implements IPlugIn

namespace plugInOne
{
    class PlugIn : IPlugIn
    {
        IPlugInHost _myHost;

        public string Name
        {
            get
            {
                return "Plug-In One";
            }
            set
            {
            }
        }

        public IPlugInHost myHost
        {
            set
            {
                _myHost = value;
            }
        }

        public void Show()
        {
        }
    }
}

And now THE CODE for the instantiation:

        String path = Application.StartupPath;
        string[] assemblyNames = Directory.GetFiles(path, "*.dll");
        plugs = new IPlugIn[assemblyNames.Length];

        for(int i = 0; i < assemblyNames.Length; i++)
        {
            string Name = assemblyNames[i];
            Name = Name.Substring(Name.LastIndexOf("\\") + 1, Name.Length - Name.LastIndexOf("\\") - 1);
            Name = Name.Remove(Name.LastIndexOf(".dll"));
            assemblyNames[i] = Name;
        }

        for (int i = 0; i < assemblyNames.Length; i++)
        {
            Assembly DLL = Assembly.Load(assemblyNames[i]);

            if(DLL != null)
            {
                try
                {
                    Object p = Activator.CreateInstance(DLL.GetType(assemblyNames[i] + ".PlugIn"));

                    if (p is DynamicApplications.IPlugIn)
                    {
                        MessageBox.Show("YES!!!!");
                    }
                    else
                    {
                        MessageBox.Show("no>?>?>>><<?????");
                    }

                    plugs[i] = (IPlugIn)p;
                }
                catch(Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }

Note the debugger shows that p is in fact instantiated and accessible

The Application always hits MessageBox.Show("no>?>?>>><<?????");

Help Please

Aiden

EDIT

P is of Type:

P is of Type:
Also

enter image description here

YET plugInOne.PlugIn implements IPlugIn

  • 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-16T03:06:32+00:00Added an answer on June 16, 2026 at 3:06 am

    Your referencing a DynamicApplications.IPlugIn and that is not the same interface which will be contained in the assembly.

    You need to get your IPlugin instance from your assembly instead of using a local instance. Your code for checking is fine, if you did something like this:

    public interface IA { }
    public class A :IA { }
    
    
    object a = Activator.CreateInstance<A>();
    if (a is IA)
        Console.WriteLine("Yes");
    

    However you are getting your A (in the above context) from somewhere else, and still trying to reference your local version of IA – therefore you need to get your interface from your assembly instead of trying to reference it locally. Perhaps you could do something like this:

    if (objA.GetType().GetInterfaces().Any(x => x.Name == "IA"))
      Console.WriteLine("Yes");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Problem: I am trying to build a recursive tree using a function and data
Problem statement I'm trying to implement my own virtual keyboard following example softkeyboard, found
Problem, simple and annoying. Im just trying to print a list of names, collected
Problem: I have a large Visual C++ project that I'm trying to migrate to
Problem: I'm trying to code a multiple choice quiz for my fellow students -and
Problem I have a piece of java code (JDK 1.6.0._22 if relevant) that implements
Problem : i'm trying to add a 2nd Jpanel in my frame but when
Problem in short: I'm trying to make a simple show/hide toggle work on just
Problem: I'm trying to integrate a slider (carousel) inside an info window of google
PROBLEM: I need to write an advanced search functionality for a website. All the

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.