Skip to main content


Showing posts from February, 2012

TFS 2010: Go offline

TFS 2010 support offline clients. This means that you can continue to work although the TFS connection is not available. So if you start up VS and attempt to load a project contained in TFS and TFS cannot be found then VS will prompt you to work in offline mode. There is only one problem: VS only does this when loading a solution.  If TFS goes offline while a solution is already open though VS will not switch to offline mode.  Instead it'll keep trying to connect to TFS and then time out.  This is really inconvenient.  So how can we tell TFS to go offline without having to reopen Visual Studio? I’m aware of 2 options: Through the tfpt command line utility in the TFS Power Tools Through the Visual Studio Go offline extension TFPT.exe Open a Visual Studio 2010 command prompt Run tfpt.exe with the ‘tweakUI’ option Select the appropriate server and click Edit. In the server properties dialog, check the Server is offline checkbox and click OK.

Ajax request returns status 0

Last week our users reported a bug that they got an alert window in their browser showing 0(zero). We traced the problem back to the following JavaScript code: $.ajax({ type: "POST", url: $(this).data('targetUrl'), cache: false, success: function(data){ //Do something }, error:function (xhr, ajaxOptions, thrownError){ alert(xhr.status); alert(thrownError); } }); The alert window shows the following message 0 and ‘undefined’. We found out that this could happen if the ajax request is getting canceled before it completes. We could reproduce the problem if we triggered the ajax request and then immediately click on a link to navigate away from the page. jQuery throws the error event when the user navigates away from the page either by refreshing, clicking a link, or changing the URL in the browser. We fixed the issue by introducing a global error handl

Just announced: TFS Express

Just before the availability of  VS/TFS 11 Beta, Microsoft introduces a new download of TFS, called Team Foundation Server Express , that includes core developer features: Source Code Control Work Item Tracking Build Automation Agile Taskboard and more… It’s a FREE version of TFS for individuals and teams of up to 5 users. The Express edition is essentially the same TFS as you get when you install the TFS Basic wizard except that the install is trimmed down and streamlined to make it incredibly fast and easy. In addition to the normal TFS Basic install limitations (no Sharepoint integration, no reporting), TFS Express: Is limited to no more than 5 named users. Only supports SQL Server Express Edition Can only be installed on a single server (no multi-server configurations) Includes the Agile Taskboard but not sprint/backlog planning or feedback management. Excludes the TFS Proxy and the new Preemptive analytics add-on. More users can b

SQL Server Profiler: Trace events from one database

I always seems to forget how to configure SQL Server Profiler to trace only a specific database. So therefore this post. Open SQL Server Profiler Click on New Trace . Connect to the database server you want to trace. The Trace Properties window is shown. Go to the Events Selection tab. On the Events Selection tab select show all columns . Now you have an extra column DatabaseName . Click on Column Filters… to add a filter. Specify the name of the database in the Like section. That’s it!

When can I use… Compatibility tables for support of HTML5, CSS3, SVG and more in desktop and mobile browsers.

You have to target a specific browser and you want to know if this browser supports a feature or not? The Can I Use website is the only thing you need. Just enter the name of a feature (e.g. Geolocation) in the Search box and you’ll get a nice overview with all the browsers(including mobile versions) and their support. Remark: I still recommend to use feature detection inside your web application(with Modernizr for example).

WCF Extensibility

This becomes really the week where I found a lot of great resources on the web. Today I discovered the perfect post to learn everything about WCF Extensibility. Carlos Figueira has written a series of posts about the (many) extensibility points from WCF (up to .NET Framework 4.0). Great stuff! Table of Contents 1. Service model extensibility 1.1. Behaviors 1.1.1. IServiceBehavior 1.1.2. IContractBehavior 1.1.3. IEndpointBehavior 1.1.4. IOperationBehavior 1.2. WCF Runtime 1.2.1. Message interception I[Client/Dispatch]MessageInspector IParameterInspector 1.2.2. Mapping between message and operation parameter I[Client/Dispatch]MessageFormatter 1.2.3. Mapping between message and CLR operations I[Client/Dispatch]OperationSelector IOperationInvoker 1.2.4. Instance [context] creation / initialization IInstanceProvider IInstanceContextProvider 1.2.5

NHibernate Mapping-by-code series

With the introduction of NHibernate 3.2, a new mapping feature was introduced: mapping-by-code. Conceptually this is similar to Fluent NHibernate and the Code First mapping in Entity Framework.  I really liked Fluent NHibernate but I had a hard time getting used to the out-of-the-box mapping-by-code feature. It' is not documented at all so I was really happy when I discovered this blog series by Adam Bar . As he says it himself it’s probably the only complete guide to mapping-by-code on the web so far. (I only found the blog of Fabio Maulo as another resource) Here is the full table of contents of the mapping-by-code series. First impressions Naming convention resembling Fluent Property Component ManyToOne inheritance dynamic component Set and Bag OneToMany and other collection-based relation types concurrency OneToOne Join Any List , Array , IdBag Map Id , NaturalId composite identifiers entity-level map

Essential JavaScript Design Patterns for Beginners

Addy Osmani has released a free ebook about JavaScript Design Patterns. Notice that the focus is on beginners. This book walks through the classical Gang of Four Design patterns(and some others…) but uses JavaScript for all the samples through the book. Even if you already know these Design Patterns by head, I can still recommend the reading because it helps to improve your JavaScript skills(It certainly helped me!). I especially liked the second part of the book where samples are shown based on jQuery. The content outline: Introduction What is a Pattern? 'Pattern'-ity Testing, Proto-Patterns & The Rule Of Three The Structure Of A Design Pattern Writing Design Patterns Anti-Patterns Categories Of Design Pattern An Introduction To Design Patterns Creational Pattern Constructor Pattern Singleton Pattern Module Pattern Revealing Module Pattern Observer Pattern Mediator Pattern

C# 5: Caller Info Attributes

One of the new features that will be available in C# 5 are the Caller Info Attributes . So what is this animal? If you are/were a C++ developer you probably know the __FILE__ and __LINE__ macros , which expand when compiled to produce a string containing the name of the current source file, and the current line, respectively. Of course C# 5.0 doesn’t support macro’s but the C# team used a different trick to introduce the CallerFilePath , CallerLineNumber and CallerMemberName attributes. A simple sample: public static class Trace { public static void WriteLine(string message, [CallerFilePath] string file = "", [CallerLineNumber] in line = 0, [CallerMemberName] string member = "") { var s = string.Format("{0}:{1} - {2}: {3}", file, line, member, message); Console.WriteLine(s); } } If you call the WriteLine method only specifying the message property the compiler would automatically fill out the optional parameters in the WriteLine met

Grant IIS 7.5 access to a certificate in certificate store

You have build this nicely secured application in ASP.NET but now you want to deploy it to IIS. Suddenly the application no longer works because you are calling some secure backend services using a certificate in your certificate store. However your IIS application pool user cannot access the certificate. How can we give IIS 7.5 the correct permissions to read a certificate from the certificate store? Open the certificates MMC. Open MMC Click File –> Add/Remove Snap-in… Choose Certificates and click Add Select Computer Account and click Finish Check if the certificate is available in the "Local Computer\Personal" cert store. Check if the private key of the certificate is marked as exportable. Right click on the certificate and choose "All Tasks --> Manage Private Keys" and "IIS AppPool\DefaultAppPool" or other user or app pool account that the IIS 7.5 app pool is using (ApplicationPoolIdentity). Tha

Windows Phone 7: 31 days of Mango e-book

Jeff Blankenburg released, with the help of a lot of other authors, the 31 Days of Mango e-book format for Kindle . If you would like to read all of these articles on-the-go, while supporting the developers that wrote them, they are now available for in the Nook and Kindle stores! Of course, if you are short of money, you can still read the online version …

TF26204: The account you entered is not recognized

While trying to import a work item definition into a team project I received the following error message: “TF26204: The account you entered is not recognized. Contact your Team Foundation Server administrator to add your account.” I found out that the issue was causes by a fault in the AssignedTo field assignment. In the rules we added an allowedvalues rule to filter the list to the project contributors. The following xml was used in the Work Item Type Definition: <FieldDefinition reportable="dimension" refname="System.AssignedTo" name="Assigned To" syncnamechanges="true" type="String"> <ALLOWEDVALUES filteritems="excludegroups"> <LISTITEM value="&quot;[Project]\Contributors&quot;" /> </ALLOWEDVALUES> <HELPTEXT>The person currently working on this task</HELPTEXT> </FieldDefinition> Did you notice the double quotes in the value. This caused TFS to m

Farewell WCF Web API… Welcome ASP.NET Web API

***Important remark: this is all unofficial information I have found while browsing through the WCF Web API discussion board. So feel free to leave a comment if some of the things I’ve found are not correct.*** WCF Web API will die soon. But in it’s ashes a new API is born, this time based on ASP.NET instead of WCF. I found the following information about this: Web API will be coming late February as part of the ASP.NET MVC 4 beta. RTM in Q3 2012 Will support ASP.NET 4.0, including a HttpClient implementation ASP.NET Web API is not limited to only MVC4, possible to host in WebForms for example. ASP.NET Web API is a separate assembly with no dependency on system.web.mvc.dll Deep integration with MVC routing to identify resources, including default values and constraints Web API uses MapHttpRoute() with a routeTemplate ("api/{controller}/{id}"), very similar to the MVC .MapRoute. UriTemplates not attributes on methods anymore. Discovers actions based on method name

Team Explorer Everywhere without Eclipse

If you are a Linux/Unix/Mac user and you want to connect to Team Foundation Server, you can use the Team Explorer Everywhere(TEE) client, an Eclipse based plugin. I got a question from some customers wanted to use the plug-in to manage TFS applications in a stand-alone fashion even though they were not developing in an Eclipse based IDE. You have 2 options in this case: Option 1: Use the command line tools. Option 2: If you prefer a visual experience, you can install the plug-in into the Eclipse Platform Runtime Binary (a cut down version of Eclipse without all the language tools for code editing etc). Remark: Don’t forget that a SP1 was released for TEE, so use the version available here .

Team Foundation Server 2010: Enable checkin policy through code

Just a quick code snippet if you want to enable check-in policies through code: var projectCollectionUri = new Uri("http://tfs2010:8080/tfs/MyCollection"); var projectCollection = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(projectCollectionUri, new UICredentialsProvider()) projectCollection.EnsureAuthenticated(); var vcs = projectCollection.GetService<VersionControlServer>(); var teamProject = vcs.GetTeamProject("SomeTeamProject"); var workItemPolicy=new WorkItemPolicy(); foreach (PolicyType policyType in Workstation.Current.InstalledPolicyTypes) { if (policyType.Name == workItemPolicy.Type) { teamProject.SetCheckinPolicies(new PolicyEnvelope[] { new PolicyEnvelope(workItemPolicy, policyType) }); break; } } In this sample I’m enabling the WorkItems policy(which is part of the Microsoft.TeamFoundation.VersionControl.Controls assembly).

SQL Server Reporting Services error: The report parameter has a DefaultValue or a ValidValue that depends on the report parameter . Forward dependencies are not valid.

For an application we are using SQL Server Reporting Services. However we had issues with one report. In this report, we have 2 parameters, e.g. OrderId & CustomerId. The value for CustomerId is calculated by executing a first query using the OrderId parameter. This is something that can be done easily in reporting services. However after configuring the parameters, compilation failed with the following error message: [rsInvalidReportParameterDependency] The report parameter ‘CustomerId’ has a DefaultValue or a ValidValue that depends on the report parameter “OrderId”. Forward dependencies are not valid.   Build complete -- 1 errors, 0 warnings It sounds like a parameter can not depend on another parameter but why did they provided this functionality? Obviously there must be something else that we did wrong. After trying almost everything you could imagine, we finally discovered that the order of the parameters are wrong. In the parameters list of your SQL Serve

Effective code reviews: ‘Buddy reviews’

Always looking for ways to improve the quality of our code, one thing I can recommend is the introduction of ‘buddy reviews’. You probably know the normal code review where maybe once a month, a technical lead or architect has a look at your code. Of course you have already moved on to another part of the code, so it’s way too late to fix all the detected issues (with an increasing technical debt as a consequence).  So let’s introduce the buddy review. It consists of meeting up with another team member informally (ideally before you check-in your code) and having a quick glance (5 - 10 mins) at each other's code at your desk or their's. This approach has the following benefits above the ‘formal’ code reviews: Problems are caught very early. You are always up to speed as to what is going on. Reviews are always very short because you are only looking at new code since the last catch up . Because the setting is informal - there is no nervous tension. They

event.srcElement vs event.Target

Web development is fun until you stumble over some browser specific issues. One bug we got last week was a script that worked in IE but not in Firefox: that.selected=function(e){ var source=e.srcElement; //Some extra code... } This one is actually a bug in IE, we are using srcElement which is an Internet Explorer proprietary element. The official property is named target , so this fixed the code: that.selected=function(e){ var; //Some extra code... }

ASP.NET MVC: Binding Arrays

The modelbinder in ASP.NET MVC is a piece of black art, converting your inputs to a nice strongly typed model. However, when binding to arrays, the DefaultModelbinder has an irritating bug. If the array is already instantiate in the model, the model binder will attempt to call .Clear() and then .Add() on the array. However arrays are fixed size lists. As a result, calling .Clear() throws a NotSupportedException as shown in the following stack trace: System.Reflection.TargetInvocationException : Exception has been thrown by the target of an invocation.--System.NotSupportedException : Collection is System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, ref SignatureStruct sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner) To resolve this, you can use the following model binder. It simply forces the model to null before invoking the default binder, effectively sidestepping the problem. public class ArrayModelBinder : DefaultMode

Visual Studio 2010: Configure the Parallel Execution of Unit Tests

Today almost every machine has multiple CPU’s or a CPU with multiple cores. Unfortunately Visual Studio 2010 is not using most of this power. However you can change the Visual Studio 2010 configuration to run Unit Tests  in parallel. How To Enable Parallel Execution of Unit Tests 1. Create a new Test Project in Visual Studio 2010 2. Right click on “Local.testsettings” and click “Open With”, choose “Xml (Text) Editor” and hit OK. 3. Expand the Execution Tag and add an additional attribute called – parallelTestCount: <TestSettings> <Description>These are default test settings for a local test run.</Description> <Deployment enabled="false" /> <Execution parallelTestCount="3"> ... </Execution> </TestSettings> You can specify the following numbers: 0 = Auto configure: Visual Studio will try to optimize based on the CPU and core count. Another number=Define the number of tests to run in parallel yourself.

JavaScript and Css Bundling and Minification

If you can’t wait until Microsoft releases ASP.NET MVC 4 (which includes bundling and minification out-of-the-box), I have good news for you. Microsoft released early bits of this feature in the Microsoft.Web.Optimization NuGet Package . This package adds support for easy minification and bundling of text-based (js, css, etc) files to your ASP.NET (MVC) web applications. The tool works by adding routes and rules to how and what it should bundle and minify. How to use it? Download and install the Microsoft.Web.Optimization package using NuGet. After installing the package, add the following code to Application_Start in Global.asax BundleTable.Bundles.EnableDefaultBundles(); BundleTable.Bundles.ResolveBundleUrl() creates an hash based on the combined files. This ensures that while combining and minifying css you're not creating caching issues that often occur when doing these kinds of optimizations. Now you can replace your existing css with this: <link href="@B

ASP.NET MVC: Error during serialization or deserialization using the JSON JavaScriptSerializer. The length of the string exceeds the value set on the maxJsonLength property.

When loading a big JsonResult from the server, the request fails with the following error message: “InvalidOperationException:Error during serialization or deserialization using the JSON JavaScriptSerializer. The length of the string exceeds the value set on the maxJsonLength property.” Thanks to this descriptive error message, its quiet clear what’s happening. The size of the JSON object exceeds the maxJsonLength value of the JavaScriptSerializer class that’s used behind the scenes. But how can we change this value? You cannot access this property directly through the JsonResult. Instead you can create your own result: public class ExtendedJsonResult : ActionResult { public ExtendedJsonResult() { this.JsonRequestBehavior = JsonRequestBehavior.DenyGet; this.MaxJsonLength=Int.MaxValue; } public override void ExecuteResult(ControllerContext context) { if (context == null) { throw new ArgumentNullException("conte