Unlocking VSTS files from a user that left the team

In the past I had used the tf.exe command line tool to unlock files that were locked by a co-worker that had left.

Today I discovered a cool free tool that makes it much easier to delete obsolete workspaces. By deleting the workspace all locks held by the workspace are automatically released.

Go to http://www.attrice.info/cm/tfs/index.htm to download the Attrice Team Foundation Sidekicks.

The Sidekicks tool worked excellent against our online Visual Studio Team Services repository.

VS2015 – Files locked after unit tests

I haven’t figured out yet why it is happening, but after a recent update I suddenly ran into an issue where when I ‘Run All Unit Tests’ in Visual Studio 2015 (Update 3) I end up with locked assemblies. This in turn does not allow me to run any subsequent tests.

Workaround is to kill the unit test processes that are locking the files using a command line (run as administrator account):

taskkill /F /IM vstest* /T


Not the most elegant solution, but it will work for now.

Unable to drop database role in SQL Server

I just ran into an issue where I was unable to delete a database role, somehow my custom database role had become the owner of the db_datareader role.

Deletion of the role was not possible due to the following error:

Error: 15138 The database principal owns a schema in the database, and cannot be dropped.

The solution is straightforward:

First find out which schema is being owned by the rolename:

SELECT name FROM sys.schemas WHERE principal_id = USER_ID( ‘<rolename here>‘ )

Then change ownership using:


After which you can drop the role

DROP ROLE <rolename here>


Annotating Entity Framework classes

A golden oldie which I seem to need to lookup everytime I use it: the MetadataTypeAttribute.

When using entity framework to generate POCO classes for my applications I frequently run into the problem that I want to annotate the fields in order to utilize MVC Client-Side validations. The POCO classes are generated so they cannot be modified with loosing the changes upon a refresh of the generated code. The MetadataTypeAtribute offers a solution. Since all generated classes are partial classes we can add a partial class and adorn it with the MetadataTypeAttribute. The attribute points to a new class which mimics the EF class and provides data annotation to describe the rules and properties of each property.



Example IsJsonRequest()

While doing some ASP.NET MVC Json programming today I discovered there is still no standard extension method for checking whether a request specifically wants a Json result.

I wanted to support both the mime type as well as a ‘format’ parameter in the url.

Here is the extension method I wrote:

public static class JsonRequestExtensions
    private const string format = "format";
    private const string json = "json";
    private const string jsonMime = "application/json";

    public static bool IsJsonRequest( this HttpRequestBase request )

        bool isJsonRequest = ( IsRequestedFormatJson( request ) == true
                               IsRequestedMimeTypeJson( request ) == true );

        return isJsonRequest;

    private static bool IsRequestedMimeTypeJson( HttpRequestBase request )
        if ( request.AcceptTypes != null )
            return request.AcceptTypes.Any( t =&gt; t.Equals( jsonMime, StringComparison.OrdinalIgnoreCase ) );
        return false;

    private static bool IsRequestedFormatJson( HttpRequestBase request )
        return String.Equals( request[format], json, StringComparison.OrdinalIgnoreCase );