Getting "fieldof" function when decompiling NET code with dnspy

110 Views Asked by At

I compiled some .NET in dnspy, and having some trouble with this statement

fieldof(<PrivateImplementationDetails>{D87A3940-7D04-49D9-B7B7-2971825FAF29}.$$method0x6000519-1)

I do understand this isn't part of c#, and is actually something from MSIL. I've seen some other posts that talk about this but the thing that I can't seem to get right is these values {D87A3940-7D04-49D9-B7B7-2971825FAF29}.$$method0x6000519-1. Would these values be referring to something specific in my context? If yes, then how do I find these values, in order to convert this to proper c# code.

1

There are 1 best solutions below

1
On

There are things that can be expressed in IL - including things that the compiler can emit indirectly via C# and the many compiler rewrite steps (async/await, expression trees, iterator blocks, lambdas/delegates, local function captures, anonymous types, etc) - that cannot be expressed directly in regular C#.

fieldof describing is one of these IL instructions. It is an imaginary C# keyword that describes certain metadata token load operations. You can't write that natively, just like you can't natively name a type <PrivateImplementationDetails>{D87A3940-7D04-49D9-B7B7-2971825FAF29} - perfectly valid in IL, but not in C#. You'll have to use reflection via GetField() in your version. The <PrivateImplementationDetails>{D87A3940-7D04-49D9-B7B7-2971825FAF29} etc here is the compiler-generated rewrite of whatever that was originally - which involves generating an entire new type to implement the simple-looking language syntax. My guess would be "async" or "lambda", but I'd need more code to say for sure.