Wednesday, August 31, 2016

Azure Service Fabric: Exposing endpoints to the outside world

The first time I created an Azure Service Fabric cluster, there was one very importing thing I forgot to configure; custom endpoints.

image

Custom endpoints allow you to expose a stateless or statefull service to the outside world. Without this the service is only accessible from inside the datacenter. The annoying thing is that you can only set the custom endpoints when you create your cluster. I couldn’t find a way to change this after the cluster is created. This means that if you forget to add a port, you have to recreate your cluster from scratch.

My current solution is to preconfigure a range of ports so I don’t run out of available endpoints while developing. To use one of the available endpoints, you have to configure the port you want to use in the ServiceManifest.xml:

<?xml version="1.0" encoding="utf-8"?>
<ServiceManifest Name="SampleService"
                 Version="1.0.0"
                 xmlns="
http://schemas.microsoft.com/2011/01/fabric"
                 xmlns:xsd="http://www.w3.org/2001/XMLSchema"
                 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <ServiceTypes>
    <!-- This is the name of your ServiceType.
         This name must match the string used in RegisterServiceType call in Program.cs. -->
    <StatelessServiceType ServiceTypeName="SampleComponentType" />
  </ServiceTypes>

<!—Some content removed—>

  <Resources>
    <Endpoints>
      <!-- This endpoint is used by the communication listener to obtain the port on which to
           listen. Please note that if your service is partitioned, this port is shared with
           replicas of different partitions that are placed in your code. -->
      <Endpoint Protocol="http" Name="ServiceEndpoint" Type="Input" Port="9003" />
    </Endpoints>
  </Resources>
</ServiceManifest>

Tuesday, August 30, 2016

Akka.NET Tip: Name your actors

A small tip when you start using Akka.NET; name your actors. By default when you create an actorref Akka.NET will assign a name for you.

var actor=system.ActorOf(Props.Create<SampleActor>());

The problem is that when you add some logging, you’ll get errors like:

An error in occured in actor akka://test/user/$a/$a/$b

which is not very useful if you want to investigate what’s going wrong.

Remark: This is an error from inside a unit test explaining the “akka://test”.

Instead using an ActorOf overload that allows you to specify a name:

var actor=system.ActorOf(Props.Create<SampleActor>(),"sample-actor");

That’s it for today!

Monday, August 29, 2016

Help! IIS logs are filling up my disks

This morning I got a warning on one of our dev servers that the disks were almost full. Whoops! Time to take some action before our dev environment goes down…

After running some diagnostics on the server we found out that most of the disk usage was caused by the IIS logs. After removing some older log files, we already felt a little better.

But how can we prevent this from happening again in the future? I could add a recurring task in my agenda and check the server every month. But there have to be some better alternatives. And no, just disabling the log files is not an option.

First thing we did is enabling folder compression. The IIS logs are simple TXT files which compress very well. Just by doing that we were able to shrink the files to about 2%(!) of their original size.

Here are the steps:

  1. Open File Explorer.
  2. Browse to the folder containing IIS log files (by default, %SystemDrive%\inetpub\logs\LogFiles).
  3. Right-click on the folder and click Properties.
  4. On the General tab of the Properties page, click Advanced.
  5. Click Compress contents to save disk space, and then click OK.

image

If you want to go one step further and really want to remove log files after X time, I would recommend creating a small Powershell script and execute it using a Scheduled Task.

Friday, August 26, 2016

AADSTS50001: The application named was not found in the tenant named .

Today we lost some investigating why we couldn’t authenticate a WinForms app using ADAL to Azure AD.

Here is the code we were using:

And here is the exception we got:

AADSTS50001: The application named .onmicrosoft.com/sample">https://<resource>.onmicrosoft.com/sample was not found in the tenant named <tenant>.onmicrosoft.com.  This can happen if the application has not been installed by the administrator of the tenant or consented to by any user in the tenant.  You might have sent your authentication request to the wrong tenant.

Trace ID: a1b52908-f2c8-4f9d-aabb-e0050ff9ca0c

Correlation ID: 9f0ec9de-2f32-47b2-9d25-11333b2bd1d6

Timestamp: 2016-08-26 10:22:17Z

If you see the error above, triple check your configuration values. Almost all the time this means you have a typo somewhere causing Azure not to find the correct information. In our situation we had a typo in the APP ID URI… Confused smile

image

Thursday, August 25, 2016

ASP.NET Web API: Remove XML formatter

ASP.NET Web API supports the concept of media formatters. Based on the content-type you set in your request headers different output can be generated. Default formatters exist for XML and JSON.

However I had a situation where I only wanted to return JSON output. Removing the XML formatter can easily be done through the Web API configuration inside your startup.cs file:

Wednesday, August 24, 2016

Web.config transformations: How to update an appsetting value

Web projects in Visual studio support the concept of web.config transformations, making it easy to update your configuration depending on the build you are using.

image

Yesterday I had a hard time to remember what the exact syntax was to update a specific appsetting. So here is a small snippet to help me remember:

Tuesday, August 23, 2016

TFS–User \ needs the 'ManageBuildResources' permission to add, update, or delete the build resources on the server.

When trying to install and configure a XAML Build controller I got the following error during the validation step:
User <domain>\<username> needs the 'ManageBuildResources' permission to add, update, or delete the build resources on the server.
Ok, no problem. I know that to configure the XAML Build and link it to a specific collection you need to be part of the Project Collection Administrators or Project Collection Build Administrators group. So I opened up the TFS Administration Console, browsed to the Collection where I want to add a build controller and clicked on Group Membership. The Global Groups window is loaded and here I can add the user(Click on Properties… –> Add).
image
Unfortunately this didn’t solve the problem. Although I had added the user to the correct groups, the error keeps appearing…
However when I added the user to the same groups through the web portal, it did work. Strange!

  • Open the Web Portal
  • Go the Administration site
  • Select the Collection level
  • Go to the Security tab
  • Select the Project Collection Administrators group
  • Click on Members and add the user

image

Monday, August 22, 2016

Team Foundation Server Administration Console: Index is out of bounds.

Got an email this morning from a customer asking me if I had seen the following error message before when opening the XAML Build Configuration inside the  TFS Administration Console:

“Index 10985 is out of bounds.”

image

This is an error I had never seen before. The thing is that the system itself was working as expected.

I asked to take a look at the logs. There we noticed that an enormous amount of event messages were generated. Could this be causing the issue?

And indeed after we cleared the event log, the XAML Build configuration appeared again. On the screen some Events related data is shown, probably this couldn’t handle the large load of messages…

image

Friday, August 19, 2016

Telerik WPF controls: XAML vs NoXAML

On a WPF project we are using the WPF controls from Telerik. Inside the Telerik folder we noticed that their are actually 2 versions of the binaries available; a ‘normal’ and a NoXaml version.

So what’s the difference and which one should I choose?

The normal assemblies contain some components together with a default set of styles and ControlTemplates. As most assemblies contain multiple components this can start to add up, as styles and templates for every component are provided. This also means that some of these assemblies are big.

To decrease the file size, a NoXaml version of the assemblies was created including only the components themselves but no xaml code(styles, brushes, controltemplates,…). However as the NoXaml version doesn’t contain any visualization information, using these alone will not make much sense. No visual output will be rendered on the screen. A NoXaml dll should therefore always be combined with a theme dll.

So which one should you pick? If you are only using a small set of components and filesize is important to you, use the NoXaml version. Otherwise you can use the ‘normal’ assemblies.

Remark: If you further want to decrease the file size, you can also decide to not use a theme dll but copy the XAML themes from the Themes.Implicit folder to your project. This allows you to remove all styling you don’t use and keep only what’s relevant.

Thursday, August 18, 2016

Akka.NET TestKit–No tests found to run.

I’m currently working on a project where I’m using Akka.NET and the Actor model. I’m amazed by the ease-of-use and how the actor model itself makes complex problems easy to implement. Anyway, I lost some time today investigating a problem that a colleague had. After installing TestKit and writing his first actor based unit test, the Test Runner explorer refused to work and the only output we got was:

No tests found to run.

image

After a few minutes I realized our mistake, we downloaded the Akka.TestKit.NUnit which is suitable for NUnit 2 and older. However we are using NUnit3, which requires a different NuGet package; Akka.TestKit.NUnit3.  After installing the correct NuGet package, our tests appeared and the problem was gone.

Kind of stupid to stumble over this problem because I had the same issue before (and even mentioned it explicitly in a previous blog post about Akka.NET; http://bartwullems.blogspot.be/2016/07/testing-your-akkanet-actors-using.html) Confused smile

Wednesday, August 17, 2016

Angular 1.5 Components: Pass event data to components

I got some trouble finding out how to pass event data from a child component to a parent component.

Here is a quick example to explain the problem:

- Imagine I have a ProductListingComponent. Inside this ProductListingComponent, I have a ProductListComponent that renders a list of ProductListItemComponents. On every ProductListItemComponent I have a “Add to Basket” button. When I click on this button I want to add the selected product to my shopping basket that is managed at the ProductListingComponent level.

image

How can I easily pass the selected product up to my parent components? Let’s find out.

Let’s first create the 3 components with their html:

Now I want to add a function to handle the click on the “Add to Basket” button and pass the product to the parent component. The correct way to pass data between child and parent component is through events. So let’s first add an ng-click directive to the button and extend our components to output an event:

Last step and that is the most tricky one is to pass the product information through the event up to the parent controller. The magic is in the html of the ProductListComponent where I create a map of local variable names and values and pass it to the event: on-select="$ctrl.onSelect({product:product})". Angular will recognize the Product property by it’s name and pass it on to the product variable in the onProductSelected function of the parent controller: on-select="$ctrl.onProductSelected(product)".

Tuesday, August 16, 2016

.NET 4.6.2–The Long Path edition

While cleaning up my RSS feeds, I noticed a new update of .NET; .NET 4.6.2. Normally I wouldn’t care so much for a minor release but this one caught my attention.

Why? Because the following fix was mentioned; Fix the 269 character file name length limitation. This  has annoyed me for a long time, and I’m happy to see that they finally fixed it. For most of my applications it didn’t matter but I had some file copy tools that got into trouble when folders were nested too deeply.

This new capability is enabled for applications that target the .NET Framework 4.6.2 (or later).

From the announcement:

The following improvements were made to enable long paths:

  • Allow paths that are greater than 260 character (MAX_PATH). Paths that are longer than MAX_PATH are allowed by the BCL. The BCL APIs rely on the underlying Win32 file APIs for limitation checks.
  • Enable extended path syntax and file namespaces (\\?\, \\.\). Windows exposes multiple file namespaces that enable alternate path schemes, such as the extended path syntax, which allows paths to just over 32k characters. The BCL now supports these paths, such as the following: \\?\very long path. The .NET Framework now primarily relies on Windows for path normalization, treating it as the “source of truth”, to avoid inadvertently blocking legitimate paths. The extended path syntax is a good workaround for Windows versions that don’t support long paths using the regular form (for example, `C:\very long path’).
  • Performance Improvements. The adoption of Windows path normalization and the reduction of similar logic in the BCL has resulted in overall performance improvements for logic related to file paths. Other related performance improvements have also been made.

More details on these changes can be found on Jeremy Kuhne’s blog.

Friday, August 12, 2016

Activate Application Insights on IIS using Powershell

There are 2 ways to start using Application Insights in your applications:

  • Option 1: You install and add the Application Insights SDK to your application. This is easy thanks to the Visual Studio integration but requires you to open, configure and release each application separately
  • Option 2: Use the Application Insights Status Monitor tool. This tool allows you to instrument a live web app with Visual Studio Application Insights, without having to modify or redeploy your code.

Remark: Note there is a third option through the Application Insights extension but this only applies to applications hosted on Azure.

After installing the Application Insights Status Monitor tool, you can pick the installed web applications that you want to monitor. Of course, ‘real’ administrators don’t use a UI but choose Powershell instead Winking smile. Application Insights supports this through the Microsoft.Diagnostics.Agent.StatusMonitor.PowerShell.dll module.

Here is an example how to use it:

  • Open a Powershell command prompt.
  • Load the Application Insights Powershell module
    • Import-Module 'C:\Program Files\Microsoft Application Insights\Status Monitor\PowerShell\Microsoft.Diagnostics.Agent.StatusMonitor.PowerShell.dll'
    • If you get an error that the module could not be loaded, check your Powershell version (use the $PSVersionTable variable). Probably you have to update it first.
  • Go to the Azure Portal
    • Create a new Application Insights subscription

image

    • Once created click on Properties

image

    • Copy the Instrumentation key from the Properties page. This key is required to link your web application to the Application Insights resource.
  • Go back to your Powershell command line
  • Type the following command to start monitoring an application
    • Start-ApplicationInsightsMonitoring -Name appName -InstrumentationKey 00000000-000-000-000-0000000
    • Hereby is -Name the name of the app in IIS and -InstrumentationKey the ikey of the Application Insights resource where you want the results to be displayed.
  • After doing this, you can check which applications are monitored using following command
    • Get-ApplicationInsightsMonitoringStatus

Thursday, August 11, 2016

Visual Studio: Improve your build output with the BuildVision extension

This week I started a new Azure project together with 2 colleagues. While debugging an issue with Azure Service Fabric, I noticed that his build output looked completely different. He was using the BuildVision Visual Studio extension.

From the website:

BuildVision activates when Visual Studio starts the process of building, rebuilding or cleaning projects (solution).

BuildVision tool window and Visual Studio Status Bar displays the current state of the process, for example: "Build solution 'MyApplication' started at 18:24:12 ..." or "Clean project 'MyProject' completed successfully at 18:25:20".

During the process, for each project the following columns are updated: State, Build Start Time, Build End Time, Elapsed Time, etc., as well as Errors, Warnings and Messages produced by MSBuild.

Indicators Panel, which is located above the table of projects, displays total number of errors, warnings and messages produced by MSBuild, the number of failed projects and successfully processed.

What I liked about the tool is that it makes it very easy to see which projects are failing to build, which is not so obvious using the default build output.

image

After installation, the tool is available from View –> Other Windows –> BuildVision

image

Thanks Gert-Jan for the great tip!

Wednesday, August 10, 2016

Enterprise Library Logging Application Block: Create a Logger instance

Last week I had to open an old codebase and fix some bugs(and some failing tests along the way). The project was using the Enterprise Library Logging Application Block. Inside the test project I got some trouble to get the Logger object working.

It took me some time to figure out that you need to configure the Logger instance first:

Tuesday, August 9, 2016

Visual Studio Performance Tools: Instrumenting signed assemblies

Inside Visual Studio if you try to instrument a signed assembly you”ll end up with an error and the performance profile session will fail.

AssemblyToProfile.dll is signed and instrumenting it will invalidate its signature. If you proceed without a post-instrument event to re-sign the binary it may not load correctly.

The problem is that instrumentiation will inject extra instrumentation probes into your code requiring the assembly to be resigned. (The whole idea of assembly signing is to guarantee that there is not tampered with your assemblies).

To solve it I used a small hack. Add the following key to your registry:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\StrongName\Verification\*,*

WARNING: This will disable strong name verification for all your signed assemblies. So remove this key after you’re done profiling.

Monday, August 8, 2016

The path of an architect

A question I get a lot is “How to become a software architect”? Most of the time I start answering by asking what they think the role of an architect is in a software project. And based on that answer we’ll start to discuss…

If you want the opinion of Juval Lowy, software legend and master architect, go watch this video on Channel 9.

And if you want to know my ideas, buy me a beer and I’m happy to share my thoughts… Smile

Friday, August 5, 2016

Comparing Cloud platforms

Today, I got 2 great resources to share:

Image from dotnetcurry.com:

azure-categorization

Cloud Comparison Header

Thursday, August 4, 2016

Upgrading Angular 2 from beta 17 to RC4–Lessons learned Part 2

This is a continuation of a previous blog post found here: http://bartwullems.blogspot.be/2016/08/upgrading-angular-2-from-beta-17-to.html

New router

We’re almost there. With the upgrade from beta to RC the Angular team throw away their first Angular 2 router implementation and build a new one. Let’s fix our code to use the updated router…

In my original code I had the following:

I updated it to the following:

Next, I extracted the router config to a seperate file and created a provider to load it inside the Angular bootstrap logic:

The code to get router data changes as well:

The information from the current route is accessible through the ActivatedRoute object. This is an observable and inside your component you can subscribe for changes. However in this sample I used the snapshot property which captures only the state on the moment we navigated to the component(which is sufficient for this example).

More information about the “new new” router can be found in the documentation: https://angular.io/docs/ts/latest/guide/router.html

Wednesday, August 3, 2016

Upgrading Angular 2 from beta 17 to RC4–Lessons learned Part 1

Last week I had to make a change to an existing Angular 2 codebase(written using Angular 2 Beta 17). Before applying the change I decided to (quickly) update the code to Angular 2 RC4. Turns out that quickly wasn’t so quick after all… A lot of things have changed between the beta and RC.

Here are some of the lessons I learned along the way:

NPM packages

The NPM packages have been renamed and do no longer contain Angular2 in their name. Instead they switched to @angular.

Here is my updated package.json:

Of course I had to update the imports inside my components as well:

import {Component} from "@angular/core";
import {ROUTER_DIRECTIVES} from '@angular/router'
import {HTTP_PROVIDERS}    from '@angular/http';

System.config changes

After updating my NPM references, I got another error:

Error: SyntaxError: Unexpected token <(…)

Angular was no longer able to load my scripts. When I took a look at the network tab in the browser I noticed that the wrong URL was used. I had to update my system.config to fix this:

 

https://www.towfeek.se/2016/05/upgrading-to-angular-2-rc1-from-beta-lessons-learned/

https://angular.io/docs/ts/latest/guide/router.html

New script references

Now that the NPM packages were imported correctly, I had good hope that everything would work. But no, a new error appeared:

Reflect.getOwnMetadata is not a function

Some new scripts had to be referenced that were not required before. So I updated my script references and added the following:

We finally started to make some progress, next issue is tackling the new router. But that is for another blog post.

Tuesday, August 2, 2016

Writing Angular 1.5 components in TypeScript

I like the addition of components to Angular 1.5. Not only are they simpler  compared to directives, they also are the way forward to Angular 2.

Yesterday I was investigating with a  colleague why a specific component didn’t work. Turned out that it was a (stupid) typo in our TypeScript code.

We first thought we had a mistake in the way we constructed the component using TypeScript. So we unnecessary lost time questioning if our TypeScript implementation was causing the issue.

Therefore I add a quick code snippet  here as a reference for future usage:

Monday, August 1, 2016

Azure Service Fabric Actor Design Patterns

Interested in using Azure Service Fabric, Microsofts Micro Services platform? But you have no clue what the actor concepts brings to the table? A great help form me was the design patterns paper by Jesse Benson.

He starts with an introduction and then continues with a range of possible patterns:

He ends the paper with some Anti-patterns.

I also would recommend the Reactive Messaging Patterns with the Actor Model book by Vaughn Vernon. Although it is written for Akka, the patterns are applicable to Service Fabric actors as well.

ActorModelBook