Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can we use TypeIdentifierAttribute in .NET without COM?

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.

like image 320
Mafu Josh Avatar asked Sep 11 '25 04:09

Mafu Josh


1 Answers

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.
like image 161
Samuel Jack Avatar answered Sep 12 '25 19:09

Samuel Jack