An object containing the value of the field reflected by this instance.
Type Reason NotSupportedException A field is marked literal, but the field does not have one of the accepted literal types. Note: For information regarding the accepted literal types, see Partition II of the CLI Specification.FieldAccessException The field reflected by the current instance is non-public, and the caller does not have permission to access non-public members. ArgumentException The field reflected by the current instance is declared neither directly in obj nor in any class from which obj derives. System.Reflection.TargetException The field reflected by the current instance is non-static, and obj is null.
If the field is static, obj is ignored. For non-static fields, obj should be an instance of a class that inherits or declares the field. Note that the return type of GetValue is Object. For example, if the field holds a Boolean primitive value, an instance of Object with the appropriate Boolean value is returned. Before returning the value, GetValue checks to see if the user has access permission.
Access restrictions are ignored for fully trusted code. That is, private constructors, methods, fields, and properties can be accessed and invoked through reflection whenever the code is fully trusted.
Starting with the net_v20sp1_long, this method can be used to access non-public members if the caller has been granted System.Security.Permissions.ReflectionPermission with the System.Security.Permissions.ReflectionPermissionFlag.RestrictedMemberAccess flag and if the grant set of the non-public members is restricted to the caller’s grant set, or a subset thereof. (See Security Considerations for Reflection.)
To use this functionality, your application should target the net_v35_long or later.
Type | Reason |
---|---|
System.Security.Permissions.ReflectionPermission | Requires permission to access non-public members of a type in loaded assemblies. See System.Security.Permissions.ReflectionPermissionFlag.MemberAccess. |