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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T16:46:11+00:00 2026-05-11T16:46:11+00:00

I’m trying to add plugins to my program, and this looks good, except that

  • 0

I’m trying to add plugins to my program, and this looks good, except that I can’t cast the correct type from the dll.
I Have a solution with several projects on it.
One of the project is a country Layer, that actually holds a CountryBase (defined as public abstract class CountryBase : CountryLayers.ICountryBase )
The Interface (public interface ICountryBase)

On Another project I have the “Implementation” for the country. This dll is loaded at run time, using this:

            Assembly assembly = Assembly.LoadFrom(file);
            //get the class from the assembly
            foreach (Type t in assembly.GetTypes())
            {
//just for debugging
                Console.WriteLine(t.FullName);
            }

            Type localType = assembly.GetType( "CountryLayers.Local");
            if (localType != null)
            {
                Country countrydata = new Country();
                countrydata.ObjectType = localType;
                countrydata.CountryObject  = Activator.CreateInstance(localType);
                countrydata.CountryObject2 = (CountryBase) countrydata.CountryObject;
                countrydata.FileName = file;
                CountryList.Add(countrydata);
            }

Where Local is the name of the class that is defined as public class Local : CountryLayers.CountryBase, CountryLayers.ICountryBase

countrydata just holds pointer. CountryObject2 is defined as CountryBase (I also tried as IcountryBase). But It always returned that the type is not convertible.

The console writeline showed that in the assembly are loaded all the classes that belongs to the countrylayer and also the local class.

So At this point I don’t know if the error is because I have everything on the same solution, or the problem is that I’m using the interface and the abstract class in a bad order. Also when create instance returns the object, that object has all the properties defined in the abstract class, but no method.

  • 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-05-11T16:46:11+00:00Added an answer on May 11, 2026 at 4:46 pm

    I solve it myself. The problem arises when you compile everything using the solution. That way, it creates dll for the interfaces also in the output of the other classes. With that in mind, I was using a plugin folder to keep the plugins, and set the VS to compile the output to that folder. It copy the derived class to that folder, along with the interface dll and the abstract implementation dll. So it made the compiler confused. I Take out every reference for projects in the VS (I change them to reference to the "compiled" dll), I compile every dll by itself, and then I only copy the dll I needed to the plugin folder, and worked.
    Anyway this link gave me a tip about the problem:
    Dynamic Loading with Reflection

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

Sidebar

Ask A Question

Stats

  • Questions 123k
  • Answers 123k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer After digging for a day and a night in the… May 12, 2026 at 12:54 am
  • Editorial Team
    Editorial Team added an answer Try the following return typeof(MyClass).Name; Or also return MethodBase.GetCurrentMethod().DeclaringType.Name; May 12, 2026 at 12:54 am
  • Editorial Team
    Editorial Team added an answer You should be able to fake this by using a… May 12, 2026 at 12:54 am

Related Questions

I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I am currently running into a problem where an element is coming back from
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.