The Close method on an ICommunicationObject can throw two types of exceptions as MSDN outlines here. I understand why the Close method can throw those exceptions, but what I don't understand is why the Dispose method on a service proxy calls the Close method without a try around it. Isn't your Dispose method the one place where you want make sure you don't throw any exceptions?
            Asked
            
        
        
            Active
            
        
            Viewed 9,970 times
        
    15
            
            
         
    
    
        Francesco B.
        
- 2,729
- 4
- 25
- 37
 
    
    
        Esteban Araya
        
- 29,284
- 24
- 107
- 141
2 Answers
10
            It seems to be a common design pattern in .NET code. Here is a citation from Framework design guidelines
Consider providing method Close(), in addition to the Dispose(), if close is standard terminology in the area. When doing so, it is important that you make the Close implementation identical to Dispose ...
Here is a blog post in which you can find workaround for this System.ServiceModel.ClientBase design problem
 
    
    
        aku
        
- 122,288
- 32
- 173
- 203
- 
                    the code using WCF Proxy Generator in VS 2008 when I add Service Reference is bad code because not good practices for disposing (close) ? – Kiquenet Nov 08 '10 at 09:49
10
            
            
        Yes, typically Dispose is one of the places you want to ensure exceptions aren't thrown. However, based on this MSDN forum thread there were some historical reasons for this behavior. As such, the recommended pattern is the try{Close}/catch{Abort} paradigm.
 
    
    
        Scott Dorman
        
- 42,236
- 12
- 79
- 110