✅ VerificationException
A friend of mine has a method that uses the Reflection.Emit namespace to create a method with the following IL:
What will happen if the field we try to access here is private/internal?
According to my friend, the code runs fine, but according to ChatGPT the following will happen:
13 Replies
Now that I've got the time to check it:
It appears I can access private fields I shouldn't have access to.
However, on .NET 4.7.2, I get a
System.Security.VerificationException
.
Does anyone know how I could get around this?
It only happens on the method call.You can do the usual trick of using reflection?
Compiled expressions also have no problem accessing private fields IIRC, although they're compiled to IL
well yeah, but this approach has it's benefits over reflection
'Compiled expressions'?
Expression.Compile Method (System.Linq.Expressions)
Compiles the lambda expression described by the expression tree into executable code and produces a delegate that represents the lambda expression.
it's one level of abstraction above il emission, it works with expression trees
How would you use such an expression in this case?
you would build up the syntax tree effectively, and then compile it using that method
there are factory functions for making syntax nodes
damn that's slow to build
but it works for .net472 so it's the only option ig
I'm still curious about this though
idk you can browse their sources and see how that compile method is implemented
it shouldn't be intrinsic
The problem is, the compile method doesn't throw it, it only gets thrown when trying to execute the method
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.