TFS Gotcha (Exception Handling)

TL;DR

Explains how to handle non-serialisable Team Foundation Server exceptions in WCF by creating custom serialisable exceptions for reliable cross-service error handling.

30 May 2007
Written by Martin Hinshelwood
1 minute read
Comments
Subscribe

When coding against team foundation server you must be aware that some of the exceptions thrown by Team Foundation Server are not Serilisable! I think that this was an oversite by Microsoft, but it is there none the less.

An example of this is; TeamFoundationServerUnauthorizedException

If you want to handle this exception accross Windows Communication Foundation  you will need to create a custom exception of the same name and re-throw this accross your services.

<DataContract()> _
Public Class TeamFoundationServerUnauthorizedException

Public Sub New()
    …
  End Sub

End Class

Make sure that you mark it as a data contract and then you can throw it when you encounter the Team Foundation Server exception:

Try
  ’ Team Foundation Server Connection Code
Catch ex As TeamFoundationServerUnauthorizedException
  Throw New FaultException(Of FaultContracts.TeamFoundationServerUnauthorizedException)(New FaultContracts.TeamFoundationServerUnauthorizedException())
Catch ex As System.Exception
  Throw New FaultException(Of System.Exception)(ex, “Failed to do team server thing”, New FaultCode("Team Foundation Server :EH:S:0001"))
End Try

This will allow you to handle Team Foundation Server exceptions for your Windows Communication Foundation service application on the client.

Technorati Tags: ALM  TFS

Smart Classifications

Each classification [Concepts, Categories, & Tags] was assigned using AI-powered semantic analysis and scored across relevance, depth, and alignment. Final decisions? Still human. Always traceable. Hover to see how it applies.

Comments
Subscribe

What to read next

Article

Creating a custom proxy class

Learn how to build a custom proxy class in .NET 3.0 for duplex communication, enabling maintainable code and easy updates when service …

Read article
Article

TFS Event Handler in .NET 3.5 Part 2 - Handling Team Foundation Server Events

Guide to implementing a resilient Team Foundation Server event handler in .NET 3.5 using WCF, including service contracts, endpoints, …

Read article
Article Engineering Excellence

Custom WCF Proxy

Explains how to create custom WCF proxies in .NET to avoid redundant class generation and object conversion when consuming Windows …

Read article