Skip to main content

Posts

Showing posts from July, 2020

Kubernetes–Troubleshooting ImagePullBackOff errors

After deploying a new pod, I couldn’t access it. Time to take a look what was going on: C:\Users\BaWu\Desktop>kubectl get pods --all-namespaces NAMESPACE              NAME                                                              READY   STATUS             RESTARTS   AGE kube-system            addon-http-application-routing-default-http-backend-7fc6fc27bj2   1/1     Running            0...

Kubernetes–the server could not find the requested resource

When trying to deploy the Kubernetes dashboard on an AKS cluster it failed with the following error message: Error from server (NotFound): the server could not find the requested resource Here was the full command I tried to execute: C:\Users\BaWu>kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/v2.0.0/aio/deploy/recommended.yaml Error from server (NotFound): the server could not find the requested resource The problem was related to the fact that kubectl supports one version   (older or newer) of kube-apiserver . I checked the installed version using: C:\Users\BaWu>kubectl version Client Version: version.Info{Major:"1", Minor:"9", GitVersion:"v1.9.0", GitCommit:"925c127ec6b946659ad0fd596fa959be43f0cc05", GitTreeState:"clean", BuildDate:"2017-12-15T21:07:38Z", GoVersion:"go1.9.2", Compiler:"gc", Platform:"windows/amd64"} Serv...

Using gRPC for your internal microservices

gRPC is a really great fit as a communication protocol between your (internal) microservices. It runs on top of HTTP/2 and gives you great performance. One caveat is that the HTTP/2 prerequisite requires by default that all communication is happening securely. So you have to setup TLS and create certificates for all your services. But what should you do when you are using Kubernetes and use TLS termination at the ingress controller level? A new feature announced in .NET Core 3.0 brings rescue. You can turn on unencrypted connections for HTTP/2 by setting the DOTNET_SYSTEM_NET_HTTP_SOCKETSHTTPHANDLER_HTTP2UNENCRYPTEDSUPPORT environment variable to 1 or by enabling it in the app context:

Razor Class Libraries–Static Content 404 issue –Part 2

I’ll continue my journey using Razor Class Libraries in ASP.NET Core. Here are my previous posts: ASP.NET Core – Razor Class Libraries Razor Class Libraries -  Views not found Razor Class Libraries – Static Content Razor Class Libraries – Clean up your Content path Razor Class Libraries -  Static Content 404 issue – Part 1 After a first colleague returned to his desk with a solution for the problem I discussed yesterday , a second colleague arrived and explained he had a similar problem. This time I could pinpoint the issue to the following PackageReference that was (still) used in a referenced project: <PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.2.0" /> Static files worked differently in .NET Core 2.2 Razor Class Libraries. The inclusion of the Microsoft.AspNetCore.Mvc v2.2.0 library broke the behaviour in ASP.NET Core 3.x applications. This reference is no longer needed as it is now a part of the...

Razor Class Libraries–Static Content 404 issue –Part 1

I’ll continue my journey using Razor Class Libraries in ASP.NET Core. Here are my previous posts: ASP.NET Core – Razor Class Libraries Razor Class Libraries -  Views not found Razor Class Libraries – Static Content Razor Class Libraries – Clean up your Content path Today I want to share an issue a colleague got when he tried to use a Razor Class Library I created. When he tried to load a static asset from the RCL, the asset was not found and a 404 error was returned to the browser. It took me a while to pinpoint the issue but in the end it turned out that the following setting in his ASP.NET Core project caused the problem: <ANCMPreConfiguredForIIS>true</ANCMPreconfiguredForIIS> After commenting out this line in the csproj file, the static assets were loaded correctly I have no clue why this solved the problem as I don’t see any relation between these features…

Razor Class libraries–Clean up your content path

I’ll continue my journey using Razor Class Libraries in ASP.NET Core. Here are my previous posts: ASP.NET Core – Razor Class Libraries Razor Class Libraries -  Views not found Razor Class Libraries – Static Content Today I want to write a small addition to my post from yesterday. As I mentioned yesterday to reference some content inside your razor views you need to use a path similar to _content/{LIBRARY NAME}. This path doesn’t look so nice. Luckily you change it to a different path name by editing the RCL project properties and adding a StaticWebAssetBasePath . Now you can access your files using /myownpath/example.css .

Razor Class Libraries–Static Content

I’ll continue my journey using Razor Class Libraries in ASP.NET Core. Here are my previous posts: ASP.NET Core – Razor Class Libraries Razor Class Libraries -  Views not found Today I want to cover how you can use static content inside your Razor Class library. To include static content(images, fonts, stylesheets,…) in your RCL you need to create a wwwroot folder in the class library and include any required files there: When packing an RCL, all content in the wwwroot folder is automatically included in the package. As this content becomes part of the DLL you cannot just reference them from the root path(“~”. Instead the path is constructed using ‘_content/{LIBRARY NAME}/’. For example to reference an example.css file that you stored inside a RCL named ‘Example.RCL’, the correct way to include this css file in your application becomes:

Kubernetes- The Virtual Kubelet

If you are looking at running Kubernetes in a cloud, sooner or later you’ll hear about ‘Virtual Kubelet’. But what is it? Let’s first go to https://virtual-kubelet.io/ and look at the definition there: Virtual Kubelet is an open-source Kubernetes kubelet implementation that masquerades as a kubelet. Mmm. That didn’t help a lot. But wait there is a second sentence, maybe that will explain everything: This allows Kubernetes nodes to be backed by Virtual Kubelet providers such as serverless cloud container platforms. Nope. Doesn’t ring a bell. Let’s try to explain this in our own words: A Kubernetes cluster is divided into two components: Control plane nodes provide the core Kubernetes services and orchestration of application workloads. Nodes run your application workloads. Kubernetes expects that a node is a virtual (or for the vintage fans a physical) machine. On every node a kind of agent is running that maanages the containers that were created...

.NET Conf “Focus on Microservices”

Every year I shout out on my blog that a new edition of .NET Conf is coming(this year November 10-12 for the .NET 5 launch). What I was not aware of is that the organizers of .NET Conf started a series of smaller events focused on specific things you can do with .NET. There have been 2 editions so far; one focusing on Blazor and the other one on Xamarin. The next one is about Microservices (who could have guessed that?) on July 30, 2020. .NET Conf: Focus on Microservices is a free, livestream event that features speakers from the community and .NET teams that are working on designing and building microservice-based applications, tools and frameworks. Learn from the experts their best practices, practical advice, as well as patterns, tools, tips and tricks for successfully designing, building, deploying and running cloud native applications at scale with .NET. Check out the agenda and the amazing list of speakers .

Razor Class Libraries–Views not found

Last week I talked about Razor Class Libraries as a nice and easy way to package and share UI components for your ASP.NET Core MVC/Razor pages application. Inside my Razor Class Library I had some shared ViewComponents that I placed in a Shared folder. Unfortunately when trying to use these ViewComponents inside my ASP.NET Core Web application, the ViewComponents were not found?! It costed me some headaches before I discovered what I was doing wrong. It is really important that your shared View(Components) reside under a Views folder as this is where Razor will search it views by convention. You can override the convention if you want to but it is probably easier to just move everything to a Views folder like I did:

MassTransit–Youtube videos

Great tip of you want to learn everything about the ins and outs of MassTransit. Chris Patterson took the time to create a great (free) video set available here: https://www.youtube.com/playlist?list=PLx8uyNNs1ri2MBx6BjPum5j9_MMdIfM9C

ASP.NET Core–Razor Class Libraries

A little known feature in ASP.NET Core (MVC/Razor pages) is the support for Razor Class libraries(RCL).  Through the RCL you can package and reuse UI components like View Components or Razor Components but also share full feature areas containing Razor view, controllers, models and so on… Let’s get started Open Visual Studio and choose Create a new project . Select Razor Class Library and click Next . Give the library a name and click on Create . Remark 1: To avoid a file name collision with the generated view library, ensure the library name doesn't end in .Views . Remark 2: Select Support pages and views if you need to support views. Otherwise only Razor components are supported. Now you can start adding your View Components and Razor components to your RCL. When building your RCL 2 DLL’s are created: One DLL containing all your logic One DLL containing your Razor views (ends with .Views ) You can now either reference this...

MassTransit–Debugging your configuration

When configuring MassTransit there are a lot of moving parts. You can have multiple endpoints, middlewares, … that all impact your application. To understand how your bus instance is wired together you can use the GetProbeResult method: Before you can use the code above, you’ll need this small extension method: More info: https://masstransit-project.com//troubleshooting/show-config.html

Entity Framework Core - Soft delete

The easiest way to implement soft delete in EF Core is through query filters. This filter can be specified when creating our EF Core model: Now every time when query for the ‘ Role ’ object an extra ‘WHERE’ clause is included that filters with IsDeleted=false. But hold your horses we are not there yet, we also have to override our SaveChanges() and SaveChangesAsyc() methods on the DbContext otherwise the ‘ Role ’ entity will still be removed from the database when we call Remove() . Remark: As a possible improvement you could generate a base class or interface for all ‘soft deletable’ entities.

Quality is a team issue

I forgot where I found the following quote but I copied and printed it out as a reminder for myself: Quality is a team issue. The most diligent developer placed on a team that just doesn’t care will find it difficult to maintain the enthusiasm needed to fix niggling problems. The problem is further exacerbated if the team actively discourages the developer from spending time on these fixes. It remains one of the biggest lessons I learned during my software career and it manifested itself in 2 ways: Supermotivated developers eager to learn new things ending in a burn/born out after six months on a project. I saw really talented and motivated people (and especially these people) getting completely fed up by an organization not willing to move. I even saw people leave the IT industry because of this. A negative trend in general software quality when one or more of the team members didn’t put the quality bar at the same level as the rest of the team. How much we tried to c...

Entity Framework - Mapping issue

I had the following entities in my domain: And this is how it was mapped through Entity Framework: Unfortunately Entity Framework got confused when I tried to create a new Role and RoleAssignment. It generated the wrong query for the RoleAssignment and tried to set the “Id” field to the Role id. To fix it I had to explicitly tell Entity Framework to use the Role_Id column to map the foreign key relationship: Strange thing is that this code was working in a previous release of the application.

Razor compilation

In .NET Core (3.x) Razor compilation happens by default at build time. This means that every time you make a change to a Razor file, you have to rebuild your application before a change becomes visible inside your frontend. This is different compared to .NET where Razor compilation happened at runtime. If you have to work a lot inside Razor, build time compilation can be annoying and slow down your development process. Luckily it is possible to enable runtime compilation for your ASP.NET Core Web application. One option you have is to enable runtime compilation at project creation: Create a new ASP.NET Core Web application in Visual Studio Check the Enable Razor runtime compilation check box when creating your project. If you have an existing project, you have to take a different approach: First install the Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation NuGet package. Update the project's Startup.ConfigureServices method to include a call...

.NET Core–Backgroundservice lifetime

.NET Core 3 introduces a new worker template that uses the concept of a BackgroundService . The BackgroundService is a base class for implementing a long running IHostedService . One important thing to be aware of is that the BackgroundService has a different lifetime than the host. This means that although a BackgroundService exits, it doesn’t mean that the host application will exit as well. One way to guarantee that the host application stops when the BackgroundService exits, is by injecting the IHostApplicationLifetime in your service and call StopApplication():