tags:

views:

13

answers:

0

In the .Net security blog article on SafeHandles, it mentions that you need to apply the ReliabilityContract attribute to the signature of the native method that closes the handle.

When we inherit from SafeHandle we have to declare a constructor, ReleaseHandle method and IsInvalid property, all of which have the ReliabilityContract applied in the base class (I used Reflector to have a look at SafeHandle):

[ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
protected SafeHandle(IntPtr invalidHandleValue, bool ownsHandle);

[ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
protected abstract bool ReleaseHandle();

public abstract bool IsInvalid { [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)] get; }

ReliabilityContract has its inherited property set to false - which I think means that the methods we override will no longer have the attribute -- so, do we need to re-apply the attribute?