TFS Gotcha (Exception Handling)

Topic(s)
Audience

Everyone

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:   

Create a conversation around this article

Share on Facebook
Share on Twitter
Share on Linkdin

Read more

Martin Hinshelwood
In organizational development and team dynamics, Agile (as the Agile Manifesto delineates) and Scrum (as the Scrum Guide outlines) guide teams not by solving their problems but by illuminating the issues that demand attention. These frameworks aim to identify and spotlight the challenges within a team or organization’s processes, effectively …
Martin Hinshelwood
This week, I participated in a Scrum.org Webinar hosted by Sabrina Love (Scrum.org Product Owner) as well as my colleagues, Joanna Płaskonka, Ph.D. and Alex Ballarin to discuss the state of learning and how immersive learning is the future of training. You can watch the video below to hear what …
Martin Hinshelwood
For a long time now I have been searching for that perfect domain that epitomised the vision, the why, of what I am trying to achieve with my customers and the industry at large. Now I have found it in http://nkdagility.com
Martin Hinshelwood
At the MVP Summit I was appalled by the number of people who asked questions about new features for supporting hierarchical tasks! I shared a disgusted look with Peter Provost and we had a quick (and I mean really quick) conversation that resulted in this post. it really comes down …