Wednesday, December 11, 2019

Autofac–Configure Container in .NET Core WorkerService

.NET Core 3.0 introduced a new WorkerService template that can be used as a starting point for long running service apps. As the worker service template didn’t use a Startup.cs file like in a traditional ASP.NET Core application, it wasn’t immediately obvious to me where I had to configure my IoC container.

So a quick tip for my future self, you can do this using the ConfigureContainer() method on the HostBuilder:

Remark: The example above is using Autofac but the approach is similar for other containers.

Tuesday, December 10, 2019

NuGet Restore error - Response status code does not indicate success: 401 (Unauthorized)

When trying to build a project in Visual Studio, it failed while downloading the nuget packages from our internal Azure Artifacts nuget store.

In the logs I could find the following error message:

C:\Program Files\dotnet\sdk\3.0.100\NuGet.targets(123,5): error : Failed to retrieve information about 'Example.WebApi.Client' from remote source 'http://tfs:8080/tfs/DefaultCollection/_packaging/892779dc-d854-4c9f-8b26-833d52585ae6/nuget/v3/flat2/example.webapi.client/index.json'. [C:\Projects\MapSU\MapSU.Server.sln]

C:\Program Files\dotnet\sdk\3.0.100\NuGet.targets(123,5): error :   Response status code does not indicate success: 401 (Unauthorized). [C:\Projects\MapSU\MapSU.Server.sln]

Directly accessing the Azure Artifacts url worked without a problem, but when I tried to do this through Visual Studio or through the commandline it failed with the error above.

I was able to solve the problem by removing the ‘vscredentials’ in the Windows Credentials manager that referred to the tfs server:

  • Open the search bar in windows and search for Credentials Manager
  • Click on Manage Windows Credentials.
  • In the Credential Manager go to ‘Windows Credentials’
  • Scroll to the list of Generic Credentials. Click on the vscredentials one and click on Remove.

Now try to access Azure Artifacts again in Visual Studio. This time I got a login popup, after entering the correct credentials everything worked again.

Monday, December 9, 2019

HTTP Error 500.35 - ANCM Multiple In-Process Applications in same Process

After switching one of our ASP.NET Core applications from out-of-process hosting to InProcess hosting, we got the following error message:

This is caused by the fact that we are running multiple applications in IIS in the same application pool. As long as we were running out-of-process this was not an issue. But when we switched to InProcess hosting it turned out that you cannot run multiple In-Process applications in the same application pool.

The solution is simple, give each application its own app pool.

Friday, December 6, 2019

.NET Core 3 - Minibook

The people from InfoQ released a free (mini)book about .NET Core. In this book, five authors talk about the current state of .NET Core 3.0 from multiple perspectives. Each author brings their experience and ideas on how different .NET Core 3.0 features are relevant to the .NET ecosystem, both present and future.

It covers the following topics:

  • Navigating the .NET Ecosystem - In 2002, .NET was released. Over the next 12+ years, the .NET developer community patiently grew at a seemingly steady pace. Then, things started evolving rapidly. Microsoft anticipated the changing ecosystem and embraced the open-source development mindset, even acquiring GitHub.
  • Interview with Scott Hunter on .NET Core 3.0 - Chris Woodruff talks to Director of Program Management for the .NET platform Scott Hunter about what developers can expect from .NET Core 3.
  • Single Page Applications and ASP.NET Core 3.0 - Web development has changed in the past few years, with the maturity of Angular, React, Vue, and others. We’ve moved from building web pages to building apps. We’ve also been shifting from rendering markup on the server to more commonly rendering it directly in the browser. But as developers continue to transition to client-side development, many are asking if they should still be using ASP.NET.
  • Using the .Net Core Template Engine to Create Custom Templates and Projects - The tooling story changed dramatically with .NET Core, because of its serious emphasis on the command line. This is a great fit for .NET Core's cross-platform, tooling-agnostic image.
  • Angular & ASP.NET Core 3.0 - Deep Dive - While there are many advantages to using Angular for building SPAs, some parts including trivial, static content such as Contact As, Licensing, etc. don’t need the extra complexity. In this article Evgueni Tsygankov shows how to build reusable Angular components that can be hosted in ASP.NET Core pages, allowing you to choose the right tool for each page.

Remark: Registration is required before you can download the ebook.

SQL Server–Find biggest tables

Did you know it is really easy to find out which tables in SQL Server use the most disk space?

  • Open SQL Server Management Studio
  • Right click on your database
  • Go to Reports –> Standard Reports

  • Choose the Disk Usage by Table report:

Thursday, December 5, 2019

ASP.NET Core - Using IClaimsTransformation with Windows Authentication

In ASP.NET Core you can implement the IClaimsTransformation interface. This allows you to extend/change the incoming claimsprincipal:

Unfortunately my ClaimsTransformer was never invoked when I used Windows Authentication in IIS.

The trick was to explicitly specify the IISServerDefaults.AuthenticationScheme:

Wednesday, December 4, 2019

Running ElasticSearch in Docker–Memlock check

While updating my docker-compose file  to the latest docker images, I noticed I had to set some extra values before I could run my ELK cluster:

I had to add an extra bootstrap check:

- "bootstrap.memory_lock=true"

and set the memlock ulimits:

        soft: -1
        hard: –1

The memory lock setting will disable swapping out parts of the JVM heap to disk. Memory swapping is bad for performance and node stability so it should be avoided at all cost.

More information:

The memlock soft and hard values configures the range of memory that ElasticSearch will use. Setting this to –1 means unlimited.