# Tuesday, 25 November 2008
« Multi Target Support | Main | New Development Snapshot »
Pseudo Custom Attributes

One of the really cool things about the CLR, when it was introduced, was the notion of custom attributes. Custom attributes provide an extensible way to add custom metadata. However, since .NET compilers virtually have to support custom attributes, it's tempting to reuse this capability for specifying non-custom metadata. It isn't efficient to encode all metadata in a generic way, hence the pseudo custom attributes were born. From most compilers they appear as normal custom attributes, but the compiler stores them in the metadata in a way that is specific to each pseudo custom attribute.

To recap, my definition of pseudo custom attributes is: Any custom attribute that modifies the metadata, but isn't stored in the CustomAttribute metadata table.

While implementing ikvmc (and later IKVM.Reflection.Emit) I looked for a definitive list of pseudo custom attributes, but there doesn't appear to be one, so I thought I'd make one:

 

ECMA CLI

IKVM.Reflection.Emit

System.Reflection.Emit

AssemblyAlgorithmIdAttribute

Yes*

No

No

AssemblyCultureAttribute

No

No

No

AssemblyFlagsAttribute

Yes*

No

No

AssemblyKeyFileAttribute

No

No

No

AssemblyKeyNameAttribute

No

No

No

AssemblyVersionAttribute

No

No

No

CodeAccessSecurityAttribute**

Yes

No

No

ComImportAttribute

No

Yes

Yes

DefaultParameterValueAttribute

No

Yes

No

DllImportAttribute

Yes

Yes

Yes

FieldOffsetAttribute

Yes

Yes

Yes

InAttribute

Yes

Yes

Yes

MarshalAsAttribute

Yes

Yes

Yes

MethodImplAttribute

Yes

Yes

Yes

NonSerializedAttribute

No

Yes

Yes

OptionalAttribute

No

Yes

Yes

OutAttribute

Yes

Yes

Yes

PreserveSigAttribute

No

Yes

Yes

SerializableAttribute

No***

Yes

Yes

SpecialNameAttribute

No

Yes****

Yes

StructLayoutAttribute

Yes

Yes

Yes

TypeForwardedToAttribute

No

Yes****

No

* Reserved only.
** Its subclasses.
*** Not part of the spec, but the spec does mention it.
**** Not in most recent development snapshot, but code is in cvs.

(System.Reflection.Emit values based on .NET 3.5 SP1)

For completeness and clarity, here is a list of non-pseudo custom attributes that are sometimes mistakenly referred to as pseudo custom attributes:

AllowPartiallyTrustedCallersAttribute

Understood by the runtime, but stored normally.

ClassInterfaceAttribute

Understood by the runtime and compiler, but stored normally.

ComCompatibleVersionAttribute

Understood by the runtime (?) and compiler, but stored normally.

DebuggableAttribute

Understood by the runtime, but stored normally.

GuidAttribute

Understood by the runtime and compiler, but stored normally.

InterfaceTypeAttribute

Understood by the runtime and compiler, but stored normally.

SecurityCriticalAttribute

Understood by the runtime, but stored normally.

SecurityTransparentAttribute

Understood by the runtime, but stored normally.

SecurityTreatAsSafeAttribute

Understood by the runtime, but stored normally.

TypeLibVersionAttribute

Understood by the compiler, but stored normally.

 

Clarifications, corrections and additions to both lists are very much appreciated.

Update: Removed incorrect claim that the runtime only supports the DebuggableAttribute (bool,bool) constructor. Thanks to Kevin M. Owen for the correction.

Tuesday, 25 November 2008 07:04:36 (W. Europe Standard Time, UTC+01:00)  #    Comments [2]
Tuesday, 02 December 2008 00:16:53 (W. Europe Standard Time, UTC+01:00)
You mentioned that the runtime appears to only understand the (bool,bool) constructor for DebuggableAttribute. I'm curious as to what exactly you mean by this, and what you're basing this observation on? It has been my experience that the overload that takes a DebuggingModes enum value works just fine, as long as that value includes DebuggingModes.Default (which Rick Byers mentions in his blog post about DebuggableAttribute at http://blogs.msdn.com/rmbyers/archive/2005/06/26/432922.aspx).
Kevin M. Owen
Tuesday, 02 December 2008 06:24:49 (W. Europe Standard Time, UTC+01:00)
Thanks. You are correct, it works fine as long as the DebuggingModes.Default value is included. I had only tried it with DebuggingModes.DisableOptimizations and by itself that value was ignored.
Name
E-mail
Home page

I apologize for the lameness of this, but the comment spam was driving me nuts. In order to be able to post a comment, you need to answer a simple question. Hopefully this question is easy enough not to annoy serious commenters, but hard enough to keep the spammers away.

Anti-Spam Question: What method on java.lang.System returns an object's original hashcode (i.e. the one that would be returned by java.lang.Object.hashCode() if it wasn't overridden)? (case is significant)

Answer:  
Comment (HTML not allowed)  

Live Comment Preview