This isn't a very serious issue, but it is interesting.

VB.NET calls RuntimeHelpers.GetObjectValue() every time an object
reference gets assigned to a field or passed as a parameter. The idea is
that boxed value types behave as values (i.e. they get copied every time
you assign them) (see runtimehelpers.cs in the Rotor source).

The problem is as follows: When GetObjectValue() is passed an
"immutable" value type, it just returns the same object. This is
incorrect, because boxes aren't *ever* immutable. The contents of a box
can always be changed (because the unbox CIL instruction returns a
*reference* to the contents of the box).

Since the list won't allow attachments, the demonstration code can be
downloaded here (4 KB):
http://www.frijters.net/boxchanger.zip
The zip includes:
  boxchanger.il   -- static method to change to contents of a boxed
Int32
  test.vb         -- demonstration of inconsistent behaviour
  boxchanger.dll
  test.exe

Please note that both test.exe & boxchanger.dll are fully verifiable.

Regards,
Jeroen

Reply via email to