3

Using windbg, is there a way to see all the custom attributes that are defined on an instance? (at class level)
And if it is possible, can I see fields values in the custom attribute?

Ohad Horesh
  • 4,340
  • 6
  • 28
  • 45
  • can i ask why you must use windbg and not some other tool like dotPeek? – wal Jan 12 '13 at 08:05
  • @wal I'm doing injection of custom attributes at run time so you can't see it in the compiled assembly. Also using the c# reflection API to check this will not work (AFAIK this is because of some kind of MS bug) – Ohad Horesh Jan 12 '13 at 19:14
  • `using the c# reflection API to check this will not work` Out of curiosity I tried this myself: http://imgur.com/L8snm can you tell me how thats different from what you're doing? – wal Jan 13 '13 at 00:40
  • 2
    In the example the attributes are applied to the types at compile time. In my case the code is compiled without the attributes. I am using the CLR profiler API (native c++) to emit the attributes at run time. The same problem exists if you emit a new type with profiler API and use reflection to look for that type. It will not show the type. I assume that this is because the manage reflection API looks at the compiled metadata. – Ohad Horesh Jan 13 '13 at 05:36

1 Answers1

0

Actually you can see the newly emitted attributes via reflection. You can use IMetaDataEmit::DefineCustomAttribute to emit the new attributes as you do and after that check their presence with reflection. I used the technique to profile my unit tests and checked successfully that my attributes were emitted (both on assembly and type level). I guess that Microsoft fixed the bug you mentioned if any.

Mihail Slavchev
  • 397
  • 1
  • 7