Skip to content
/ Michaël Hompus

Recently, I was using a YAML file for storing some data for a pet project. To work with this YAML in a .NET application, I use the excellent YamlDotNet library by Antoine Aubry. One of my properties was a URL. Deserializing went fine, but when serializing back to a YAML file, things were not going as intended. In this short article, I will explain how I did fix this.

Recently, I was using a YAML file for storing some data for a pet project. To work with this YAML in a .NET application, I use the excellent YamlDotNet library by Antoine Aubry.

One of my properties was a URL. Deserializing went fine, but when serializing back to a YAML file, things were not going as intended.

In this short article, I will explain how I did fix this.

The setup

I have a quite simple piece of YAML describing a website with a name and URL.

website:
name: Blog
url: https://blog.hompus.nl

To represent this in my application, I created a simple POCO.

public class Website {
public string Name { get; set; }
public Uri Url { get; set; }
}

Deserializing

When deserializing the file, this works completely as expected. As you can see in the VSCode debugger:

Deserialized data, as shown in the VSCode debugger

Serializing

Now I want to serialize the object back to YAML. However, it ends up looking quite different than before.

website:
name: Blog
url: &o0
absolutePath: /
absoluteUri: *o0
localPath: /
authority: blog.hompus.nl
hostNameType: Dns
isDefaultPort: true
pathAndQuery: /
segments:
- /
host: blog.hompus.nl
port: 443
query: ""
fragment: ""
scheme: https
originalString: https://blog.hompus.nl
dnsSafeHost: blog.hompus.nl
idnHost: blog.hompus.nl
isAbsoluteUri: true
userInfo: ""

This was not what I expected.

So how can we encourage YamlDotNet to store the property as a string?

YamlMember

The YamlMember attribute can solve this problem. It has the SerializeAs property that allows to set the Type that the serialize must use during serialization.

For this situation, I choose the String type.

public class Website {
public string Name { get; set; }
[YamlMember(typeof(string))]
public Uri Url { get; set; }
}

And when generated the YAML file again, it looks like how I intended it.

website:
name: Blog
url: https://blog.hompus.nl/
Filed under C#
Last update:
/ Michaël Hompus

Using Docker images for your Azure web app is not brand-new functionality. But if you want to deploy your container-based web app using ARM templates and use your own Azure container registry, you might discover it's not as straightforward as you might think. In this article we will walk through the steps how we can make a connection to the container registry. In the end we will also make sure we do not have to pass along the password during the deployment.

Using Docker images for your Azure web app is not brand-new functionality. But if you want to deploy your container-based web app using ARM templates and use your own Azure container registry, you might discover it’s not as straightforward as you might think.

In this article we will walk through the steps how we can make a connection to the container registry. In the end we will also make sure we do not have to pass along the password during the deployment.

read more…
Filed under Azure
Last update:
/ Michaël Hompus

These times should not prevent us from sharing knowledge and keep learning about great new technologies. For this, Info Support organized the lockdown lectures. I was honored to take part in this series and have people learn about the Open Application Model (OAM) and the Distributed Application Runtime (Dapr). Here I share with you the recording and slides.

These times should not prevent us from sharing knowledge and keep learning about great innovative technologies. For this, Info Support organized the lockdown lectures.

I was honored to take part in this series and have people learn about the Open Application Model (OAM) and the Distributed Application Runtime (Dapr).

read more…
/ Michaël Hompus

When working with ARM Templates, chances are you have set a value that was a Storage Account Connection String. For example as the value of an appsetting, or as a secret in Azure Key Vault, which I did as an example in a previous blog post. However, this does not result in the most maintainable and readable piece of JSON. Even worse if you have multiple connection strings in the same template. In this article I will show that adding a User-Defined Function to our template can improve on this.

When working with ARM Templates, chances are you have set a value that was a storage account connection string. For example, as the value of an appsetting, or as a secret in Key Vault, which I did as an example in a previous article.

However, this does not result in the most maintainable and readable piece of JSON. Even worse if you have multiple connection strings in the same template.

In this article I will show that adding a user-defined function to our template can improve on this.

read more…
Filed under Azure
Last update:
/ Michaël Hompus

This weekend I was speaking at WordCamp Nijmegen about the possibilities of hosting a WordPress site using Microsoft Azure. I’m sharing my Dutch slides here, and soon I hope to add the recording for WordPress TV in this post as well.

This weekend I was speaking at WordCamp Nijmegen about the possibilities of hosting a WordPress site using Microsoft Azure.

Even though I expected to get some criticism for dropping the Microsoft name at such an event, I felt very welcome. I experienced the event as a large group of very warm people from all over the world that are coming together to help each other out. And like Microsoft nowadays, they set a high standard with their code of conduct (in English).

read more…
Filed under Azure
Last update: