Monday, February 29, 2016

Adventures in Xamarin Forms

simulator-screen-shot-24-oct-2015-11-23-42_iphone6_gold_side21With the recent announcement that Microsoft is buying Xamarin, I thought it was time to have a second look at Xamarin Forms(I took a first look more then a year ago, so hopes are that it evolved a lot in the meanwhile).

The most interesting resource I could find is the Adventures in Xamarin Forms blog by Jonathan Yates in which he describes the lessons he learned while creating the Mountain Weather application.

Friday, February 26, 2016

Using NPM behind a company proxy

Yesterday I was giving training about Team Foundation Server when I wanted to demonstrate the tfs-cli tool. However when I tried to download the tool using npm install -g tfx-cli it failed. A company proxy was preventing npm to be able to connect to the outside world.

To fix this, you have to update the npm configuration file and specify the the proxy setting. Open a command prompt and run the following command to do this:

npm config set proxy http://proxy.company.com:8080

We also noticed that the first time we did this it didn’t work because the user wasn’t authenticated yet at the proxy level. However after opening up a browser and surfing to a site outside the company network the user was authenticated to the proxy and we were able to call npm.

Thursday, February 25, 2016

TFS 2015–Uploading Build vNext tasks without enabling basic authentication

I talked about the tfs-cli tool before. This tool allows you to create and upload your own custom build steps both in VSTS and TFS on premise. Unfortunately to be able to use it on your local TFS instance, you have to enable Basic Authentication. If you don’t want to do that, you have to use the REST api’s to upload your custom task.

Although this is certainly possible, it’s not that easy to do. Luckily a colleague spend some time creating a Powershell script to simplify the process:

Just invoke the script, specify the location of your custom tasks, the url of your TFS instance and your windows credentials.

Wednesday, February 24, 2016

Arc42–Resources for software architects

As an architect, part of my job, lies in design, communication and documentation. Documents, (UML)diagrams and white board pictures(my favorite Open-mouthed smile!) are necessary parts of defining and describing a system & application architecture.

arc42-logo[4]

Last week I heard a podcast where they were talking about arc42, a template for documenting of software architectures:

image_thumb[1]

Here is a sample of documentation created with it: https://rawgit.com/aim42/htmlSanityCheck/master/build/html5/hsc_arc42.html

More information:

Tuesday, February 23, 2016

Avoid the use of task.Result

With the introduction of async/await, asynchronous programming in .NET  becomes a breeze. However with great power, comes great responsability.

I see a lot of programmers starting enthousiastic with the Task Parallel Library and the async/await syntax but a few days later, they start to report strange bugs and issues with their code(or even worse the end-user start to report this).

Almost all the time it is because developers didn’t fully understand what’s going on behind the scenes and when we dig into the code, there is almost all the time the following code(or similar):

var httpClient = new HttpClient();
var t = httpClient.GetAsync("http://stackoverflow.com", HttpCompletionOption.ResponseHeadersRead);
return t.ContinueWith(t1 => t1.Result.Content.Headers.ToString());

If you use the code above in a Console application, it should not be a problem. However if you try to do the same thing inside an ASP.NET(MVC) application you’re into trouble. Why? What makes this code different in ASP.NET vs a Console application. The answer is the SynchronizationContext. In ASP.NET, only one thread can handle a request at a time. You can do some parallel processing, but only one thread would have the request context. This is managed for you by the ASP.NET SynchronizationContext.

The moment a task attempts to resume within the ASP.NET request context when there is already a thread in that context, the thread will block and you’ll end in a deadlock situation. In the example above, the current thread will be blocked until the t1.Result is available. But t1 is waiting for the result of task t which will not be able to resume as the current thread is blocked.

How can we fix this?

Easiest solution is to correctly use the async/await syntax here and avoid the usage of the Task api’s:

var httpClient = new HttpClient();
var result = await httpClient.GetAsync("http://stackoverflow.com", HttpCompletionOption.ResponseHeadersRead);
return result.Content.Headers.ToString();

Some useful links:

Monday, February 22, 2016

A devops mindset for your enterprise

DevOps is cultural change that impacts every part of your organisation not only the development and operations departments. I hear a lot of (IT) organisations talk about DevOpsbut if you talk to their managers they have no insights in the delivery capability of their organisation, and even worse they are not interested. This is a recipe for disaster. It’s exactly the same reason why I see Agile fail in organisations, because it requires the exact same cultural shift. Without management involvement, the impact will be minimal…

Why are managers not interested?

Taking a look at most organisation structures brings some answer. You see a separate team of operation guys, a separate team of developers, a separate team of testers, … . Each of these teams have their own managers, living in their own silo with their own goals. These managers are very rarely accountable for the end-to-end delivery of customer value. A manager responsible for ‘server operations’ will never care about the health of the applications running on these servers as long as the servers themselve are healthy.

silos

I do believe that DevOps can make a difference for your organisation, but not without a change in organisation structure and mindset…

Time for a DevOps revolution…?

Friday, February 19, 2016

Domain Driven Design in 15 minutes

Domain Driven Design is new to you? Or you have heared about it and want to learn more? And you don’t have much time?

The guys from DZone created a new DZone RefCard about Domain Driven Design. In one big article they walk through the main concepts. Just enough to get you excited Smile!

image

Thursday, February 18, 2016

Bootstrap modal dialog issue: Dropdown always closes

Last week, a developer reported a strange issue: he was using the Bootstrap modal dialog. On this dialog he added a dropdown control(a  KendoUI control in this case). The problem was that each time he opened up the dropdownlist to  select an item, it immediatelly closed again.

When we investigated the issue, we noticed that the moment the dropdown list opened, the Bootstrap modal dialog steals the focus and a blur event is triggered. This blur event makes the control close again.

After further investigation we discovered what was causing this behavior. The dropdownlist creates a hidden popup element on the page. This popup element is not part of the modal dialog content. This means that when you click on the popup element, the modal dialog thinks that you want to move out of the dialog and therefore triggers a blur event.

I noticed the same behavior not only with the KendoUI DropDownList control but also with other dropdown controls like  Select2.

We found 2 possible solutions that solve the issue(both of them work)

  • Solution 1 – Remove the tabindex=-1 from the modal dialog:

<div class="modal fade" tabindex="-1" role="dialog">
    
<div class="modal-dialog"> <!-content removed—></div>
</div>

  • Solution 2 – (In case of Kendo UI) Use the .appendTo method on the DropDownList control to add the popup to the content of the modal dialog:

.Popup(p => p.AppendTo("[selector]"))

Wednesday, February 17, 2016

TFS Widget blog series

The ALM rangers are unstoppable. Now they created a blog series about building your own widgets for the Dashboard in TFS 2015.

(For this screen, in case you have no clue: )

1033_Overview-Dashboard_1B6E90BD 

Here is the full series:

Tuesday, February 16, 2016

Team Foundation Server 2015: Add Git and TFS Version Control repositories to the same Team Project

With Team Foundation Server 2015 Update 1, Microsoft introduces the option to add Git repositories to your existing team project created with TFVC (or vice versa). This is great if you are using TFSVC today and want to move to Git but you want to keep your work items, build definitions, and other data.

How?

  • Open the Team Project web portal inside your favorite browser
  • Go to the Code hub

image

  • Open the repository selector

image

  • Click on New repository…

image

  • Choose the repository type and a name for your repository
  • Click on Create
  • That’s it!

Remark 1: You need Visual Studio 2015 Update 1 to see the repository appear inside the Team Explorer view. VS 2015 RTM and previous version only show the repo created with the team project

Remark 2: It is possible that you have to configure some security settings to allow access to the new repository type. This will be fixed in Update 2. In the meanwhile you can follow the steps as explained here: https://msdn.microsoft.com/en-us/Library/vs/alm/Code/team-projects

Monday, February 15, 2016

JavaScript Memory Management Masterclass

If you want to learn more about the ins and outs of Memory Management inside the browser and the JavaScript runtime (and you should!), have a look at this great video by Addy Osmani:

Friday, February 12, 2016

TFS Build vNext–Build tasks cannot handle spaces in repository path

I’m a big fan of the new build system in TFS. However it’s still a learning process for me. After adding the NuGet Packager task, my build failed with the following error message:

1.  T02:04:25.2941286Z Creating Nuget Arguments:
2.  2016-02-08T02:04:25.3019414Z --ARGS: pack d:\b\3\_work\1c61834d\my demo project\NugetSpecs\test1.csproj.nuspec -OutputDirectory d:\b\3\_work\1c61834d\demo -Properties Configuration=Release -version 2016.2.8.1
3.  2016-02-08T02:04:25.3029180Z Invoking nuget with pack d:\b\3\_work\1c61834d\my demo project\NugetSpecs\test2.csproj.nuspec -OutputDirectory d:\b\3\_work\1c61834d\demo -Properties Configuration=Release -version 2016.2.8.1
4.  2016-02-08T02:04:25.3029180Z D:\b\3\agent\worker\tools\NuGet.exe pack d:\b\3\_work\1c61834d\my demo project\NugetSpecs\demo3.csproj.nuspec -OutputDirectory d:\b\3\_work\1c61834d\demo -Properties Configuration=Release -version 2016.2.8.1
5.  2016-02-08T02:04:28.3342844Z pack: invalid arguments.
6.  2016-02-08T02:04:28.3391674Z usage: nuget pack <nuspec | project> [options]
The generated Nuget Pack command is indeed incorrect. Why? Because the task didn’t escape the path to my .nuspec file correctly. As highlighted in yellow, you could see that the path contains some whitespaces. 
I was planning to fix the issue, but thanks to the power of open source, someone already fixed the specific task: https://github.com/Microsoft/vso-agent-tasks/commit/3a7ac0f11ebe17cb110cca904cc8313319c4ad97

But how do I get this updated task on my on premise TFS server?

Here are the steps you need to take:
  • Download and install the TFX command line tool using NPM:
    • npm install -g tfx-cli
  • Before you can use the TFX tool with your on premise TFS server, you have to enable basic authentication:
  • Clone the vso-agent-tasks repository on your local file system
    • Find the path to the task you want to upload
    • In our case this is c:\github\vso-agent-tasks\tasks\NugetPackager
  • Run the TFX tool and specify the path of the specific task
    • ~$ tfx build tasks upload --task-path c:\github\vso-agent-tasks\tasks\NugetPackager
  • You can check that the task is uploaded succesfully by executing the following command
    • ~$ tfx build tasks list

More information:

Thursday, February 11, 2016

ASP.NET MVC–Precompile Razor views on Release build

Last week I was investigating slow startup times of an ASP.NET MVC web application. We were able to trace the root cause to a really complex Razor page. This was the first page that was loaded and takes a long time to compile.

By default Razor compilation happens the first time a Razor page is requested by the browser. However you can change this and prebuild all the Razor pages by adding the MvcBuildViews tag to your .csproj file:

<?xml version="1.0" encoding="utf-8"?>
<Project>
    <PropertyGroup>
        <MvcBuildViews>true</MvcBuildViews>
        

Unfortunately it had a large impact on the build times making debugging a pain for the developers. So in the end we decided to only precompile Razor on a release build. Therefore we had to add 2 MvcBuildViews tags with a condition:

<MvcBuildViews Condition="'$(Configuration)'=='Debug'">false</MvcBuildViews>
<MvcBuildViews Condition="'$(Configuration)'=='Release'">true</MvcBuildViews>

Wednesday, February 10, 2016

TFS Build vNext: SonarQube error - Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=512m; support was removed in 8.0

After installing SonarQube and enabling the integration with our TFS Build server, the moment of truth was there. It was time to kick off our first build and let SonarQube analyze our code quality.

Unfortunately the SonarQube build task failed with the following error:

image

2016-01-29T08:26:36.0469894Z ##[error]Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=512m; support was removed in 8.0

2016-01-29T08:26:36.0479657Z ##[error]The SonarQube Scanner did not complete successfully

Whoops! It seems that SonarQube is providing an option flag ‘MaxPermSize’ which was removed in Java 8.0.

To fix it, I did the following:

  • Log in on the server where you have SonarQube installed
  • Go to the System properties and open the Environment Variables
  • Search for the SONAR_OPTS environment variable
  • Remove the MaxPermSize=512m; from the value
  • Save your change and reboot the server

That should do the trick…

Tuesday, February 9, 2016

SpecFlow v2 finally arrived

We had to wait for it a long time, but now it’s finally there, a new release of SpecFlow; my favorite  Behaviour-Driven Development (BDD) tool.

So what’s new?

Important changes in SpecFlow V2 include:

  • All components upgraded to .NET 4.5.
  • Upgraded to the new Gherkin 3 parser
  • Support for parallel SpecFlow tests within the same AppDomain
  • Visual Studio integration has been separated to a separate project
  • Support for xUnit 2.0 and NUnit 3.0, including parallel test execution. The older providers have been retained and renamed (to xunit.1 and nunit.2 respectively).
  • Ability to determine the execution order of hooks (e.g. [BeforeScenario])
  • Extensible table conversions and comparisons for CreateSet, CreateInstance, CompareToSet and CompareToInstance.
  • Access the details of the currently executed step with ScenarioContext.StepContext
  • Display tags in NUnit test adapter in Visual Studio
  • Better regular expression suggestions generated for missing steps with quoted parameters
  • Steps base class provides properties for thread-safe access to feature, scenario and step contexts
  • Scenario and feature context can be injected to the binding class, avoiding static ScenarioContext.Current and FeatureContext.Current accessors
  • Better matching of column names to property names by removing characters that are invalid in property names
  • Small improvements in the DI framework
  • Easily configure SpecFlow to work with MSTest using the SpecFlow.MsTest NuGet package
  • Test execution report now includes “tags” in the NUnit report, which can be displayed using a custom XSLT
  • Removed .NET runtime version from generated file headers to avoid unwanted changes

If you never used SpecFlow before, now is a good time to try it out. Writing tests will never be the same again…

Remark: If you are already using SpecFlow today, don’t forget to check the upgrade guide: http://www.specflow.org/updating-to-specflow-2/

Monday, February 8, 2016

Shrink your environmental footprint: IFIXIT

With a small boy in the house, our pile of broken things kept growing and growing, not only toys but also electronic devices(think remote controls and XBOX controllers Smile) and other household stuff ended on the pile after he tried to use it in a kind of destructive fashion.

Instead of throwing everything away, it was time to dust off my soldering and electronic skills and try to repair some of these things. This was easier said than done as most electronic devices(including toys) seems to not be created with repairability in mind.

Luckily I discoved IFIXIT, an amazing site with lots of great (free!) step-by-step repair manuals. If you want to stop throwing things away and start with shrinking your environmental footprint, this site is a great help.

image

And if you need some tools to get your repair work going, they sell repair kits, spare parts and tools. I’m a fan!

Friday, February 5, 2016

F# Beginner Tip: File order matters!

One thing that you should be aware of when you build your first ‘real’ F# application, is that in F# file order matters. F# requires files (and code within) to be in dependency order. This means that you have to rethink how to organize your code. Have a look at the following post on http://fsharpforfunandprofit.com/(great site btw for every F# developer out there):

http://fsharpforfunandprofit.com/posts/recipe-part3/

Luckily Visual Studio provides some context menu options that allow you to re-order the files inside your F# projects:

image

Thursday, February 4, 2016

SonarQube: Error when running it as a Windows Service

After installing SonarQube, you can run it as a Windows Service by executing the InstallNTService.bat file inside the %SONARQUBE_HOME%/bin/windows-x86-32/InstallNTService.bat folder.

However when I tried to do this, it failed silently and I only saw the following on the command line:

--> Wrapper Started as Service

Launching a JVM...

Wrapper (Version 3.2.3) http://wrapper.tanukisoftware.org

Copyright 1999-2006 Tanuki Software, Inc.  All Rights Reserved.

<—Wrapper Stopped

Luckily the documentation brought the answer.By default the SonarQube windows service is installed under a local account but you need administrative permissions to be able to run SonarQube.

Here are the steps to fix it:

  • Open the list of installed services on your system(search for services.msc)
  • Right click on the SonarQube service in the list
  • Click on Properties
  • Go to the LogOn tab
  • Change the LogOn from a Local System Account to another account with administrative permissions

Wednesday, February 3, 2016

SonarQube configuration error: Failed to load the sqljdbc_auth.dll cause : no sqljdbc_auth in java.library.path

While configuring a SonarQube server to use SQL Server, I encountered the following error after enabling Integrated Security in the JDBC connection string. After adding “integratedSecurity=true” I got the following error message when I tried to start SonarQube:

WARNING: Failed to load the sqljdbc_auth.dll cause : no sqljdbc_auth in java.library.path

Let’s fix this:

That should do the trick…

Tuesday, February 2, 2016

ASP.NET 5 & ServiceFabric: Unable to locate Dependency Microsoft.AspNet.Server.WebListener >= 1.0.0-rc1-final

When adding an ASP.NET 5 Web API to my ServiceFabric solution, restoring the NuGet packages failed with the following error message:

Errors in Projects\MyActor\Web1\project.json
    Unable to locate Dependency Microsoft.AspNet.Server.WebListener >= 1.0.0-rc1-final
Restore complete, 73193ms elapsed


image

This is an issue in the current version of the SDK. You can fix it by executing the following steps:

  • Go to your ASP.NET 5 web project
  • Open the project.json file
  • Add a space to the file and save it
    • This will trigger a NuGet Package restore and the missing dependency will be downloaded

Monday, February 1, 2016

ASP.MVC: Async/Await in action filters

A colleague was having some trouble with his ASP.NET MVC 4 application. Whe he started his application, the process “hanged” and he had to kill the w3wp process to be able to restart.

We were able to pinpoint the problem to a call to an async method inside an Action Filter:

It seems that there is no support for async filters in ASP.NET MVC 4. The call to .Result in the action filter resulted in a blocking operation making the whole application pool unavailable. We solved it by switching to a non async version of the api.

Remark: Note that ASP.NET Web API does have support for async action filters.