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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T04:03:35+00:00 2026-06-09T04:03:35+00:00

With public abstract class CompositionPlugin { … } and public class MyCompositionPlugin : CompositionPlugin

  • 0

With

public abstract class CompositionPlugin { ... }

and

public class MyCompositionPlugin : CompositionPlugin { ... }

I want to check if an object’s type is equal to a given type:

public class Framework {

    public IList<CompositionPlugin> CompositionPlugins = new List<CompositionPlugin>();

    public CompositionPlugin GetCompositionPlugin(Type ofType)
    {
        foreach (CompositionPlugin plugin in CompositionPlugins)
        {
            if (plugin.GetType().Equals(ofType))
                return plugin;
        }

        throw new ArgumentException("A composition plugin of type " + ofType.FullName + " could not be found");
    }
}

Where the method is called like this:

Framework framework = new Framework();
// Adding the plugin to the framework is done by loading an assembly and
// checking if it contains plugin-compatible classes (i.e. subclasses
// of <CompositionPlugin>)
framework.RegisterAssembly("E:\\Projects\\Framework\\MyPlugin\\bin\\Debug\\MyPlugin.dll");
CompositionPlugin plugin = framework.GetCompositionPlugin(typeof(MyCompositionPlugin));

Yet, when testing, this check always fails, even though I most definitely have that type of object in the list that I request.

In my understanding, it should return the first instance of MyCompositionPlugin that is found inside the CompositionPlugins-List.

Is my type check wrong? Why? How is it done correctly?

  • 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-09T04:03:37+00:00Added an answer on June 9, 2026 at 4:03 am

    Turns out, the information I initially left out of the question, deeming it not important, was so after all.

    The MyCompositionPlugin and CompositionPlugin are both defined in different assemblies, that the executing program loads dynamically at runtime.

    The .NET-Runtime now consideres a type loaded from a different assembly another than the one referenced by the executing assembly, rendering the MyCompositionPlugin-Type in the Program to be considered unequal to the MyCompositionPlugin loaded from another assembly, even if they are actually the same.

    The solution to comparing the two for equality (in that they are the same “Class” in the common sense) is to break it down to a string-equality of the defining assemblies, which is arguably dirty, but does the trick.

    public CompositionPlugin GetCompositionPlugin(Type ofType)
    {
        foreach (CompositionPlugin plugin in CompositionPlugins)
            if (ofType.AssemblyQualifiedName.Equals(plugin.GetType().AssemblyQualifiedName))
                return plugin;
    
        throw new ArgumentException("A composition plugin of type " + ofType.FullName + " could not be found");
    }
    

    Cudos to Paolo Falabella who pointed to this question

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

Sidebar

Related Questions

[ProtoContract] public abstract class Animal { [ProtoMember(1)] public abstract string Type { get; set;
Given the class': public abstract class AbstractEntity { public virtual Guid Id { get;
Given the following code : public abstract class Participant { private String fullName; public
InputStream class defined as- public abstract class InputStream extends Object Then how System class
I have abstract class public abstract class BaseClass { public delegate void ContextMenuClickHandler(object sender,
// AvgTemp.java public abstract class AvgTemp { public void notifyReceived ( String eventName, Object
Given the following: public abstract class Base { // other stuff public static void
See the definition of System.Array class public abstract class Array : IList, ... Theoretically,
public abstract class ExeCommand { private static object commandHandler; public static object CommandHandler {
Consider the following code: public abstract class Test1 { public object Data { get;

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.