Skip to main content

Posts

Run a GraphQL backend as an Azure Function

I typically run my GraphQL backends as an Azure App Service or Azure Container app, but today I had to create a really small API. I was wondering, could I use an Azure Function to host this API? Let's find out in this post. Creating an Azure Function App Let’s start by creating our Azure Function App. I’ll use Visual Studio in this example but you could perfectly use Visual Studio Code as well. Open Visual Studio and choose Create a new project . In Create a new project , enter functions in the search box, choose the Azure Functions template, and then select Next . In Configure your new project , specify a project name and click Next . in Additional Information, set the following values: Functions worker: .NET 6 (there is no reason to run this as an isolated worker) Function: HTTP Trigger Authorization level: Anonymous   Click on Create to create our Function app and the HTTP Trigger function. We’ll update our...

dotnet format issue - FileNotFoundException: The file '' does not appear to be a valid project or solution file.

I’ve blogged previously about ‘dotnet format’ and how it can help you to keep your code formatting and style consistent. In one of these posts I’ve shared the following example as a way to apply a specific code formatting rule(file scoped namespaces in this example): dotnet tool update --global dotnet-format dotnet format Example.sln --severity info --diagnostics=IDE0161 However when I recently tried to execute the example above, it no longer worked ?! Instead I got the following error message: Unhandled exception: System.IO.FileNotFoundException: The file 'IDE0161' does not appear to be a valid project or solution file.    at Microsoft.CodeAnalysis.Tools.Workspaces.MSBuildWorkspaceFinder.FindFile(String workspacePath)    at Microsoft.CodeAnalysis.Tools.Workspaces.MSBuildWorkspaceFinder.FindWorkspace(String searchDirectory, String workspacePath)    at Microsoft.CodeAnalysis.Tools.FormatCommandCommon.ParseWorkspaceOptions(...

InvalidOperationException: No authenticationScheme was specified, and there was no DefaultChallengeScheme found.

Sometimes, you have of these days where you stumble from one issue to another. This was (unfortunately) one of these days. The story started when I tried to run an ASP.NET Core project I had to review. (Always my first check, can I follow the instructions in the readme.md file and get the source code up and running easily on my local machine). But this day, no luck, as ASP.NET Core decided to give me the following error message: InvalidOperationException: No authenticationScheme was specified, and there was no DefaultChallengeScheme found. Typically this indicates that no authentication is configured, but a look at the Program.cs file didn’t bring me closer to the solution. Everything looked okay: Then I noticed the following in my Visual Studio, I was running the application through Kestrel. Could that be the reason? I switched to IIS Express and ran the application again. Now I was able to start the application succesfully. Enabling Windows Authentication for Kest...

Azure DevOps - Use variable in workspace mapping

Today I was having a look at a build pipeline of one of my clients. On this specific project there are still using Team Foundation Version Control(TFVC) which is still supported in Azure DevOps. If you don't remember TFVC(or never used it before), one of the differences between TFVC and Git is the way it handles branches. In Git a branch is a pointer to a commit whereas in TFVC a branch is visualized as a separate folder in your source control tree. In the image above we have a Main branch and a branch per release in the Release folder. You can map this folder structure to your local file system through a workspace mapping . This allows you to have multiple branches available and active at the same time on your local machine. When using TFVC in your build pipeline, you also need to configure a workspace mapping to specify which folders should be downloaded and mapped on the file system of the build server. Notice that I'm hardcoding the Release number(2.5) in t...

ElasticSearch - Invalid NEST response built from a successful (200) low level call on POST

After upgrading our ElasticSearch cluster, I restarted our batch processing service. This service gets a data offload every night from an external party and we'll use this data to build up our search index. The BulkAllObservable helper As a lot of documents should be indexed, I use the BulkAllObservable helper to optimize the process. This helper is part of the ElasticSearch.NET client and takes care of all the complex retry, backoff or chunking logic. It gives you full control on how the underlying BulkApi should be called. This code worked perfectly before. Unfortunately after upgrading to Elastic 8.3, that was no longer the case. Enable compatibility mode I saw the following error message in the logs: BulkAll halted after receiving failures that can not be retried from _bulk   at Nest.BulkAllObservable`1.HandleDroppedDocuments(List`1 droppedDocuments, BulkResponse response)  at Nest.BulkAllObservable`1.<BulkAsync>d__20.MoveNext() --- End of s...

.NET Core Dependency Injection–Check if a service is already registered

It is way too hot today to write a long post, so I focus on a small but useful new feature in .NET 6. As I mentioned before in most of my projects I'm using Autofac as the Inversion of Control container of my choice. One of the features that Autofac has to offer is the IsRegistered method which allows you to check if a specific type is already registered in the IoC container. Starting from .NET 6, you can do a similar thing with the Microsoft DI container using the IServiceProviderIsService interface: You first need to resolve the interface from the container and then you can call the IsService() method to see if the service can be resolved through the container or not: That’s it! Time to cool down(literally)…

.NET Core Dependency Injection–Using multiple implementations of the same interface

On most of my projects I'm using Autofac as the Inversion of Control container of my choice. However this introduces an extra dependency and it comes with a (although short) learning curve. So o a newer project, I decided to give the built-in IoC container in .NET Core another try. The standard DI stuff worked as expected, however there was one situation where I had to investigate a little further. Let me explain... Registering multiple implementations for the same interface Here is my use case; in my application I’m using Serilog . One of the features that Serilog has to offer is the concept of an enricher . This allows you to enrich your log messages  with extra information in an easy way. As some of my enrichers required dependencies I wanted to register those enrichers in my  IoC container. When using Autofac I would have done this like this: To do the same thing using the Microsoft DI container is not that different: The AddTransient() method will not over...