SCA1007: GetObjectValue
Do not use RuntimeHelpers.GetObjectValue.
Example
object clone = RuntimeHelpers.GetObjectValue(box); // SCA1007
Func<object, object> cloner = RuntimeHelpers.GetObjectValue; // SCA1007
object same = box; // OK: the object itself
How to Fix
Use the object as it is.
Details
RuntimeHelpers.GetObjectValue returns a clone of a boxed struct, field by field, so it copies every non-copyable value that the struct holds. For any other object it returns the object itself.
Every use gets a warning, a call and a method group alike, whatever the type of the argument: nobody calls it on something that cannot be a boxed struct. So this warning can appear in a project that copies nothing.
See Also
These articles explain the rule behind this warning:
- Boxes and Unions - boxes, and what takes a value out of one.
Didn't add this analyzer yourself? See Why Am I Seeing This?