Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to dispose of a System.ServiceModel.ClientBase<TChannel>?

Tags:

idisposable

I'm using a class that extends ClientBase<>:

interface IService {}
class MyServiceClient : ClientBase<IService> {}

The issue I run into is that FxCop complains that a class with MyServiceClient as a member variable should also implement IDisposable and dispose of MyServiceClient.

ClientBase has an explicit implementation of Dispose(), which means a simple MyServiceClient.Dispose() doesn't compile. I have to explicitly cast to IDisposable. Why is that? Is it a signal that I shouldn't use Dispose()? Should I use Close() instead?

like image 352
Steve Robbins Avatar asked Oct 22 '25 16:10

Steve Robbins


1 Answers

In Close and Dispose - which to call? is suggested that Close and Dispose should have the same implementation. Here is an example wrapper class (usage) which calls Close in the Dispose function. So it seems fine to call Close.

like image 110
wimh Avatar answered Oct 27 '25 06:10

wimh