Microsoft FxCop 1.312

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

In the report of the FxCop analysis:

CriticalError, Certainty 95, for
"TypesThatOwnDisposableFieldsShouldBeDisposable"
{
Target : "Receiver" (IntrospectionTargetType)
Resolution : "Implement IDisposable on 'Receiver' as it instantiates members
of the following IDisposable types: System.Net.Sockets.Socket"
Help :
"http://www.gotdotnet.com/team/fxcop...hatOwnDisposableFieldsShouldBeDisposable.html" (String)
Category : "Microsoft.Design" (String)
RuleFile : "Design Rules" (String)
Info : "Types that declare disposable members should also implement
IDisposable. If the type does not own any unmanaged resources, do not
implement a finalizer on it."
Status : Active (MessageStatus)
Fix Category : Breaking (FixCategories)
}

But Socket has the Dispose method as protected so I can not invoke it.
Should I or shouldn't I Implement IDisposable in this case???
 
The protected Socket.Dispose method that takes a boolean is not actually the
Socket's implementation of the IDisposable.Dispose method. Socket uses an
explicit implementation, so you would need to cast to IDisposable to call
Dispose. However, the Socket.Close method does exactly this, so you can
simply call that instead.
 
Back
Top