William Bartholomew

Musings on software engineering, technology and Aspergers Syndrome.

Archive for the ‘programming’ Category

Only Catching Exceptions When Debugger Isn’t Attached

leave a comment »

When building applications that will run unattended (for example from a scheduled task or a Windows Service) you usually need to be quite aggressive when catching exceptions. This can be quite detrimental to the debugging experience and there are two common workarounds to this problem:

Configuring Visual Studio to Break When Exceptions Are Thrown

By default Visual Studio will break when exceptions are unhandled, but if you have aggressive exception handling then most exception will be handled and Visual Studio will never break. You can configure Visual Studio to break when an exception is thrown rather than only if it’s unhandled from the Debug | Exceptions menu. This shows the dialog below which allows you to choose for each exception type under which circumstances Visual Studio will break.

image3

Adding Breakpoints Manually

The alternative is to manually add breakpoints in the exception handlers you’re interested in debugging as shown here:

image4 

But Wait… There Is Another Option

Visual Basic allows you to add a filter to your exception handlers specifying a condition under which the exception handler will be in effect.

We can leverage this to make our handler only catch the exception if there isn’t a debugger attached which means if a debugger is attached the exception will be unhandled and the debugger will automatically break.

We use the shared IsAttached method of the Debugger class in the System.Diagnostics namespace to detect if a debugger has been attached as shown in this example:

Try
    teamFoundationServer.EnsureAuthenticated()

Catch ex As TeamFoundationServerException When Not Debugger.IsAttached
    My.Application.Log.WriteException(ex)
    Environment.Exit(ExitCode.TeamFoundationServerExceptionAuthenticating)

Catch ex As WebException When Not Debugger.IsAttached
    My.Application.Log.WriteException(ex)
    Environment.Exit(ExitCode.WebExceptionAuthenticating)

End Try

Written by wbarthol

October 6, 2008 at 10:13 am

Posted in dotnet, programming

Setting Default Values for Workflow Dependency Properties

leave a comment »

When setting default values for dependency properties in Workflow Foundation there are two steps:

  1. Pass a PropertyMetadata object containing the default value to the DependencyProperty constructor (Line 8). This defaults the value of the property to the passed value.
  2. Apply the DefaultValue attribute to the property (Line 14). This provides the default value to the PropertyGrid which allows functionality such as the property appearing bold if the value is different to the default and the right-click Reset option to set the property back to the default. 

For example:

   1:  Private Const DefaultPort As Integer = 25
   2:   
   3:  Public Shared PortProperty As DependencyProperty = _
   4:      DependencyProperty.Register( _
   5:          "Port", _
   6:          GetType(Integer), _
   7:          GetType(SendEmail), _
   8:          New PropertyMetadata(DefaultPort) _
   9:      )
  10:   
  11:  <Description("Port")> _
  12:  <Category("Input")> _
  13:  <Browsable(True)> _
  14:  <DefaultValue(DefaultPort)> _
  15:  <DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)> _
  16:  Public Property Port() As Integer
  17:      Get
  18:          Return (CType((MyBase.GetValue(SendEmail.PortProperty)), Integer))
  19:      End Get
  20:      Set(ByVal Value As Integer)
  21:          MyBase.SetValue(SendEmail.PortProperty, Value)
  22:      End Set
  23:  End Property

Written by wbarthol

September 17, 2008 at 3:33 pm

Posted in dotnet, programming

Workflow Tracking Events Not Available Until Workflow Completes

leave a comment »

I was using Workflow Foundation as part of an internal process recently and I couldn’t work out why the tracking events generated by the SqlTrackingService weren’t being written to the tracking database until the workflow completed or was terminated.

The issue was that the SqlTrackingService is transactional by default and the transaction isn’t committed until the workflow completes or is terminated. This can be changed by setting the IsTransactional property to False before adding the service to the WorkflowRuntime’s services collection.

http://msmvps.com/blogs/theproblemsolver/archive/2006/09/28/Tracking-in-Workflow-Foundation.aspx

Written by wbarthol

September 17, 2008 at 1:43 pm

Posted in dotnet, programming

Stop Visual Studio 2008 from Running Built-In WCF Service Host

leave a comment »

I was working on a project recently where I had a solution with a project that self-hosted a WCF service and another project containing the service itself.

When running the solution with self-hosted project as the startup Visual Studio would also run the built-in WCF service host resulting in a clash for URLs/ports.

The solution is in the WCF Options tab in the service’s project properties. If you clear the Start WCF Service Host When Debugging Another Project In The Same Solution checkbox Visual Studio won’t run the built-in WCF service host unless the service project is the start-up project.

image

Written by wbarthol

September 17, 2008 at 9:32 am

Posted in dotnet, programming

Calculating Total Size of a Directory Using LINQ

with one comment

Dim totalSize As Decimal = (Aggregate file In New System.IO.DirectoryInfo(“c:\dev\”).GetFiles(“*.*”, IO.SearchOption.AllDirectories) Into Sum(file.Length)) / 1024 / 1024

Written by wbarthol

December 31, 2007 at 12:24 pm

Posted in dotnet, programming

Schemas for Work Item Type Definitions

leave a comment »

I’m doing a lot of work with Work Item Type Definitions and for those that don’t know the Visual Studio SDK includes schemas for these that can be used in Visual Studio (and other XML editors) to provide Intellisense capabilities.

Rob Caron blogs about this here. For those that don’t want to download the whole SDK he also provides a direct download of just the schemas.

Written by wbarthol

December 27, 2007 at 7:54 am

Posted in programming, teamsystem

Cannot Remove Reference from Web Site Project in Visual Studio 2008

leave a comment »

I just ran into an issue where I right-clicked a Web Site Project in Visual Studio 2008 and chose Property Pages and then tried to remove a reference. However, whenever I clicked the Remove button the dialog just flashed and the reference remained.

The issue turned out to be that the web.config file (where the reference information is stored) was read-only. Making the file read-write again solved the issue.

Written by wbarthol

December 24, 2007 at 8:24 am

TFS/VSTS "Rosario" Feature Requests

leave a comment »

I’ve raised a number of feature requests on Connect for the “Rosario” release of TFS/VSTS. If you think any of these are valuable please vote for them:

Single Item Link Control

Business Rule to Restrict Area and Iteration By Depth

Save As for Test Plan

Bulk Add Test Passes

Restrict Work Item Linking

Camano: Assign Test Passes and Test Suites to Individuals

Written by wbarthol

December 21, 2007 at 12:58 pm

Posted in programming, teamsystem

Making TextPad Standard

with one comment

We have a site license for TextPad but I always find myself lusting after other editors (such as Notepad++).

I reinstalled TextPad today and instantly remembered the one thing that annoys me most about it… Ctrl+F is not Find, F5 is…

Luckily like most applications it does however allow changing key bindings, so I made the following changes and I’ll see how I go:

SearchFind – Ctrl+F

SearchFindNext – F3

FileManage – F5

Written by wbarthol

December 19, 2007 at 8:44 am

Posted in programming, utility

Introduction to Work Item Customisation

leave a comment »

I’ve uploaded my Introduction to Work Item Customisation presentation to SlideShare. I originally presented this at the Queensland VSTS Users Group.

Written by wbarthol

August 13, 2007 at 7:06 pm