Tuesday, November 30, 2021

GraphQL HotChocolate 12 - Updated Application Insights monitoring

It seems that with every release of HotChocolate, I can write a follow up post. With the release of HotChocolate 11, I wrote a blog post on how to integrate it with Application Insights.

With the HotChocolate 12, there was again a small update in the available interfaces and API’s.

Let’s check the changes we have to make…

  • First of all, our diagnostic class should no longer inherit from DiagnosticEventListener but from ExecutionDiagnosticEventListener.
  • The signature of the ExecuteRequest method has changed as well. Instead of returning an IActivityScope it should return an IDisposable:
  • This also means that our RequestScope no longer needs to implement the IActivityScope interface but only needs to implement IDisposable:

Here is the full example:

Monday, November 29, 2021

C# 10–Change an existing project to file scoped namespaces

C# 10 introduces file scoped namespaces. This allows you to remove the ‘{}’ when your source file only has one namespace(like most files typically have).

So instead of writing:

you can now write:

To apply this for an existing project written in C# 9 or lower, you can do this in one go.

Therefore set the language version of your project to C# 10:

Now we need to update our .editorconfig file and add the following line:

After doing that Visual Studio will help us out and we can use “Fix all occurences in Solution” to apply it in one go:


Thursday, November 25, 2021

Running Azure on your laptop–Part 2 - Azure Arc for Developers

In the previous post in this series I talked about Azure Arc and it’s multiple flavors. Although one Azure managed control plane for all your resources no matter if there are on premise, on Azure or hosted at another cloud provider sounds great if you are an IT ops guy(or girl) but why should you care as a developer as well?

It is important to understand that the Azure Arc story has 2 dimensions.

1. Arc enabled infrastructure

The first dimension is the Arc enabled infrastructure. This is the part that I already talked about and that allows you to connect and control hybrid resources like they are native Azure resources. This allows you to use additional Azure Services like Azure Policy, Azure Monitor, and so on to govern, secure and monitor these services.

2. Arc enabled services

The second dimension is Arc enabled services. Once you have an Arc enabled infrastructure, you can start to deploy and run Azure Services outside Azure while still operation them from Azure. This allows you to run Azure Services like App Services, Functions, Logic Apps, API Management and Event Grid outside Azure!

How does this work?

Azure application services with Azure Arc is available as an extension on Azure Arc-enabled Kubernetes clusters that allow you to easily install the App Service control plane on Kubernetes and start deploying your applications to it. So in our next posts, we’ll focus on how to Arc-enable your Kubernetes cluster and get the Azure Application services cluster extension up and running.

Wednesday, November 24, 2021

Running Azure on your laptop– Part 1–What is Azure Arc?

Before I dive into the details on how to get Azure Arc up and running on your laptop, it would be a good idea to start with a short introduction.

Therefore we first have to dive in how Azure works. The hearth of the Azure ecosystem is the Azure control plane. This control plane manages all the resources you can find in Azure. It helps you to inventorize, organize and govern all resources and multiple tools exist that can help you to interact with it (think ARM templates, Bicep, Terraform, Pulumi, …)

You probably know this control plane better as the Azure Resource manager. It controls and manage all the Azure resources which can be as big as a Kubernetes cluster and as small as a static ip address. These resources run inside an Azure region, one of the datacenters that Microsoft has all around the world.

So where does Azure Arc fits into this picture?

If we bring Azure Arc into the picture, we can bring resources that are not running on Azure to the Azure control plane and by doing that we can start using all services on top of the Azure Resource manager to secure, monitor, protect, … these resources. These resources can be running in your own datacenter or even at one of the other cloud providers!

Today, Azure Arc allows you to manage the following resource types hosted outside of Azure:

  • Servers - both physical and virtual machines running Windows or Linux.
  • Kubernetes clusters - supporting multiple Kubernetes distributions.
  • Azure data services - Azure SQL Managed Instance and PostgreSQL Hyperscale services.
  • SQL Server - enroll instances from any location with SQL Server on Azure Arc-enabled servers.

I think this really is a game changer as it allows you to start using all the knowledge, experience and tooling you’ve build up on Azure outside the Microsoft datacenters.

The future looks bright…

Tuesday, November 23, 2021

Running Azure on your laptop–Introduction

As mentioned yesterday I promised to write a series of follow up posts about my ‘Running Azure on your laptop’ session. I’ll use this post as a placeholder to point to the different parts.

Microsoft is more and more embracing a hybrid cloud approach. As part of this evolution, an increasing amount of ‘Azure only’ services become available outside Azure. This idea is not new, people who work long enough in the Microsoft ecosystem maybe remember Azure Pack,  which was a way to install Azure software on your own hardware.It gave you the Azure portal and some of it’s services. I never tried it myself and I don’t know any customer who used it in the wild.

A couple of years later, Microsoft announced the Azure Pack’s successor, Azure Stack. This was a hardware appliance, that you could install in your own datacenter. Over time, the name evolved to Azure Stack Portfolio as multiple flavors of Azure Stack became available. Azure Stack is still available today and keeps evolving.

At Ignite 2019, another solution was introduced; Azure Arc. With Azure Arc, Microsoft hybrid story continues by allowing you to manage resources from within Azure while they can be running practically anywhere.

Azure Arc supports managing & operating Virtual Machines, SQL servers, and Kubernetes clusters that run on any cloud provider, hybrid scenario, or on-premises infrastructure that is fully managed through Microsoft Azure.

If you want to learn more about Microsoft hybrid cloud story, check https://azure.com/hybrid.

I’ll write multiple posts but I’ll make sure to update this post with the full list.

Monday, November 22, 2021

VisugXL - Running Azure on your laptop using Azure Arc

Last weekend I gave a presentation at VisugXL about Azure Arc. I’ll write a few follow-up posts explaining the steps I took to get it all up and running(and where I got into trouble).

If you can’t wait until then, here is already the presentation:

Friday, November 19, 2021

.NET 6–Breaking changes

Although Microsoft takes a lot of effort to maximize backwards compatibility, migrating to .NET 6 can result in breaking changes that might affect you.

So before you start to upgrade have a look at the list of breaking changes maintained here: https://docs.microsoft.com/en-us/dotnet/core/compatibility/6.0

Tuesday, November 16, 2021

Azure DevOps–Run a tool installed as npm package

As part of our build pipeline we wanted to use GraphQL Inspector to check if our updated GraphQL schema contained any breaking changes.

GraphQL Inspector is available as a commandline tool and can be installed through NPM.

So the first step was to use the NPM task to install the tool:

But now the question is how can we invoke the installed tool?

This is possible thanks to NPX. NPX stands for Node Package Execute and it comes with NPM. It is an npm package runner that can execute any package that you want from the npm registry.

I added a command line task to invoke npx:

Remark: When using NPX you even don’t need to install the package first. This means that the NPM task I created first is not necessary.

Monday, November 15, 2021

ASP.NET Core - Build a query string

What is wrong with the following code?

Nothing you would say? What if I passed ‘Bert & Ernie’ as the searchterm parameter?

The problem is that I’m using string interpolation to build up the query. This could be OK if you have full control on the passed parameters but in this case it is input coming from a user. The example above would lead to an incorrect query string.

Writing the correct logic to handle ampersands, question marks and so on would be a challenge. Luckily ASP.NET Core offers a QueryHelpers clas with an AddQueryString function:

public static string AddQueryString(string uri, string name, string value);

public static string AddQueryString(string uri, IDictionary<string, string> queryString);

Let’s update our code example to use this:

That's better!

Wednesday, November 10, 2021

Azure DevOps Pipelines–A local file header is corrupt

A colleague contacted me with the following question; he tried to run a specific Azure Pipelines build but before even one build task could be executed, the build failed.

I asked him to send me the logs and he shared the following screenshot:

As you can see the build fails in the ‘Job initialization’ phase while downloading a specifc task ‘VersionAssemblies’.

The strange this was than when I searched for this build task I couldn’t find it between the list of installed extensions on the Azure DevOps server.

I took a look at the Azure DevOps marketplace and even there this specific build task was non-existent. Strange!

At least this explained the error message I got, as the build pipeline probably couldn’t find the task either.

In the end I fixed it by introducing an alternative build task that achieved the same goal(updating the AssemblyInfo with a build number).

Tuesday, November 9, 2021

Azure DevOps–SonarQube error

As part of our build pipelines, we run a code analysis through SonarQube. After moving SonarQube to a different server, our Azure DevOps pipelines started to fail.

When I opened the build logs, I noticed the following error message:

ERROR: JAVA_HOME exists but does not point to a valid Java home folder. No “bin\java.exe” file can be found there.

I logged in on our SonarQube server and checked the value of the JAVA_HOME environment variable:

JAVA_HOME = c:\program files\Zulu\zulu-11\bin\

Based on the error message above, it seems that the SonarScanner expects that we don’t include the ‘bin’ folder. So I updated the environment variable to:

JAVA_HOME = c:\program files\Zulu\zulu-11

After rescheduling the build, the SonarQube analysis task completed succesfully.

Monday, November 8, 2021

GraphQL Crash Course

If you want to get started with GraphQL, you can have a look at the following video:

Remark: This is part of a bigger course that is available on Udemy.