Every method defined in .NET has a header, and in this header is a maxstack value:
.assembly Hello {} .method public static void Main() cil managed { .entrypoint .maxstack 1 ldstr "Hello, world!" call void [mscorlib]System.Console::WriteLine(string) ret }
It is specified explicitly in a fat (Microsoft's naming, not mine) header, and is implicitly 8 in a tiny header.
But what is it for?
Well, the documentation states that it specifies the maximum number of entries the stack will contain during execution of this function.
Good, excellent, very useful, you might think - now the JIT/execution engine doesn't have to figure out how much stack space to allocate, just use this value.
But no, it's not that simple. Maxstack specifies the maximum number of stack entries, not the maximum number of stack bytes. In .NET the size of a stack entry is essentially unbounded, as value-types are stored directy on the stack; unlike reference types, which have a reference (of known size) stored in the stack.
A value-type can be as large as you like: System.Drawing.Rectangle is 16 bytes, and you can define your own to be multiple kilobytes, or larger (I'm not saying this is recommended, but it's certainly possible).
This means that Dot Net Anywhere has to do a full stack analysis of each method to calculate the number of bytes required for the stack, and essentially ignores the maxstack value (it actually does use it, but not for anything important, and could easily manage without - see the source for details - JIT.c).
Which makes me wonder - why is it even there? It appears to serve no useful purpose.
If you happen to know the answer, please let me know...