3

I am curious if it is possible to make 2 interfaces in .NET (either in the same assembly or in separate assemblies) that can be treated as equivalent, using the new TypeIdentifierAttribute attribute. I have not found a way.

I've seen some stuff on the internet that suggest this eventually would be possible, but it kinda looks like the current implementation is only for COM interops. I understand the immediate intentions for this were for embedding COM interops. I am not dealing with COM interops.

Also, I am not interested in discussing why I would want to do this, I don't want to lead this question to other types of solutions. Let's just say that I'm experimenting and I want to see if there is anything we can do with TypeIdentifierAttribute.

Mafu Josh
  • 2,523
  • 1
  • 23
  • 25

1 Answers1

3

According to both the documentation, and anecdotal evidence, it is possible to make type equivalence work with standard, non-COM, interfaces.

From the documentation, it seems that you don't need the TypeIdentifierAttribute if your interfaces live in different assemblies. To have two interfaces treated as equivalent, you just need to:

  1. Make sure they both have the same name, and live in the same namespace.
  2. Apply the GuidAttribute to them both, assigning them the same Guid.
Samuel Jack
  • 32,712
  • 16
  • 118
  • 155
  • Thank you, your second link led me to http://blogs.msdn.com/b/mshneer/archive/2008/10/28/advances-in-net-type-system-type-equivalence-demo.aspx which had demo source code that was very helpful. – Mafu Josh Aug 20 '10 at 05:10
  • @MafuJosh, the link seems to be broken. Do you happen to still have the source code? – Yacoub Massad Mar 07 '19 at 14:50
  • Sorry I don't. And I can't find this blog archived anywhere. – Mafu Josh Mar 09 '19 at 14:32
  • The link isn't broken any longer. – Mafu Josh Dec 12 '19 at 15:00
  • The aforementioned link is now broken again, but the same post can be found under: https://learn.microsoft.com/en-us/archive/blogs/mshneer/advances-in-net-type-system-type-equivalence-demo – Wiktor Bednarz Oct 21 '20 at 16:52