#Roslyn code generator question:

I'm noticing that ISymbol.MetadataToken is always returning 0 for me, for both classes and methods. Obviously at runtime those things have non-0 metadata token values.

Is it expected that they'll always return 0? Is this a consequence of building for Native AOT?

@bradwilson I don't know, but my hunch says that it will be 0 for symbols declared in source (where you don't know what the metadata token will be until you emit the binary), and non-zero for symbols coming from metadata references (since you already know the token for those)
@KirillOsenkov These are definitely symbols in source. 👍🏼
@KirillOsenkov Interestingly I discovered that calling MetadataToken at runtime in Native AOT throws (a good reminder that you don't know what actually works until you publish and run for real). I'm mildly surprised there's no analyzer warning about this. But now I know for sure it's a dead end...
@bradwilson yeah I'm guessing much of the metadata is getting inlined or erased for Native AOT
@KirillOsenkov Opened an issue, though I'm not sure if Roslyn is the right repo for it. https://github.com/dotnet/roslyn/issues/82301
Consider adding an analyzer for MetadataToken for Native AOT · Issue #82301 · dotnet/roslyn

I will note that I'm not 100% sure where the Native AOT analyzers live, so this may be opened in the wrong place. Brief description: Using MetadataToken from a Type appears to always throw. I'm sug...

GitHub