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

  • Home
  • SEARCH
  • 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 7739037
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T08:25:13+00:00 2026-06-01T08:25:13+00:00

I’m looking for all implementations of IHandle<> in my assembly. public interface IHandle<T> where

  • 0

I’m looking for all implementations of IHandle<> in my assembly.

public interface IHandle<T> where T : class, IEvent, new()

Those classes looks like

public class IHandleEventX : IHandle<EventX>{...}

public class IHandleAnotherEvent : IHandle<AnotherEvent>{...}

Currently, I got the following code.

aLoader.LoadImplementationOf(typeof(IHandle<>));

// my aLoader class method
public void LoadImplementationOf(Type genericInterface)
{
    // theres another foreach here, to iterate over all assemblies
    foreach (Type aType in allMyAssemblies.GetTypes())
    {
        var interfaces = aType.GetInterfaces();
        foreach (var currentInterface in interfaces)
        {
            if (!currentInterface.IsGenericType) { continue; }
            // the statement below always return false
            if (currentInterface.GetGenericTypeDefinition() == genericInterface)
            {}

            // those two statement (FullName and AssemblyQualifiedName), works as expected
            if (currentInterface.GetGenericTypeDefinition().FullName == genericInterface.FullName)
            {}
            if (currentInterface.GetGenericTypeDefinition().AssemblyQualifiedName == genericInterface.AssemblyQualifiedName)
            {}

            // those below also fail
            if (currentInterface.GetGenericTypeDefinition().IsAssignableFrom(genericInterface))
            {}
            if (genericInterface.IsAssignableFrom(currentInterface.GetGenericTypeDefinition()))
            {}
            // can't do currentInterface.GetGenericTypeDefinition() is genericInterface compiler error
        }
    }

Why comparing types fail, but comparing types fullname property works ?
Also, whats the best way to do this?

Edit: I rewrote the sample, using only one assembly and IsAssignableFrom worked. I’ll investigate and update here later to see why isn’t working using more than one assembly – as @HansPassant pointed out


It’s working now, but I’m not sure why…
I was working with 3 assemblies.

  • Asm Loader, there was only de ALoader class there
  • Asm Domain, with interfaces IHandle<>, IEvent<> and classes IHandleEventX, IHandleAnotherEvent
  • Asm Test, my test project, I was calling aLoader.LoadImplementationOf(typeof(IHandle<>)); from here.

Projects References.

  • Loader doesnt references any project.
  • Domain references Loader (there was another IInterface on Loader, implemented on Domain)
  • Test references both Loader and Domain.

So I moved my interfaces IHandle<> and IEvent<> from Domain to Loader and removed the reference from Domain to Loader, now, its works.

Its still not clear why the IsAssignableFrom failed when IHandle<> was in the domain. It only worked when my IHandle<> and ALoader are in the same assembly.


Well, in the end, that was my fault, I was loading de assembly in two load contexts.

  • 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-01T08:25:14+00:00Added an answer on June 1, 2026 at 8:25 am

    That’s because Type.FullName doesn’t fully describe a type. You only get the namespace name and the type name. But .NET also includes the properties of the assembly in which the type resides into the type identity. Display name, [AssemblyVersion], Culture, PublicKeyToken and (indirectly) ProcessorArchitecture. You want to compare Type.AssemblyQualifiedName instead.

    The diagnostic for failure like this is that the source code that contains the interface definition is getting compiled into multiple assemblies. Which in itself is almost always a mistake, you want to make sure that such an interface type only exists in one assembly. And any assembly that uses the interface type has a reference to it so they all use an identical type.

    The rules for type identity were loosened somewhat in .NET 4, a type can be identical if it has the same GUID. The underlying core for the Embed Interop Types feature. But that only applies to [ComImport] types, I doubt that’s the case here.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I would like to run a str_replace or preg_replace which looks for certain words
Let's say I'm outputting a post title and in our database, it's Hello Y&#8217;all
I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I've got a string that has curly quotes in it. I'd like to replace
I want use html5's new tag to play a wav file (currently only supported
I am doing a simple coin flipping experiment for class that involves flipping a
I am trying to render a haml file in a javascript response like so:

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.