I am working on an interpreter for MSIL code. When it comes to boxing, there are some known restrictions, for example, it's impossible to box byref-like structs.
Regarding System.RuntimeArgumentHandle, I noticed that for .NET Framework (unlike .NET Core), System.RuntimeArgumentHandle is just a struct, so it seems that boxing is allowed. However, the following program is invalid:
locals init (valuetype [mscorlib]System.RuntimeArgumentHandle V_0)
ldloca.s V_0
initobj [mscorlib]System.RuntimeArgumentHandle
ldloc V_0
box [mscorlib]System.RuntimeArgumentHandle
pop
Furthermore, if I use an old Visual Studio 2008 and try to compile the following code, it fails with the error "Cannot convert type 'System.RuntimeArgumentHandle' to 'object'":
var o = (object)new RuntimeArgumentHandle();
Why is it not allowed to box RuntimeArgumentHandle, and how does the compiler understand this?
Boxing
System.RuntimeArgumentHandleis a special case in the spec. ECMA-335, 5th edition, 8.2.1.1, emphasis added: