Home > Back-end >  IConfiguration causes socket hang up error
IConfiguration causes socket hang up error

Time:07-03

Background:

I have a small asp.net web api project that I am trying to upgrade from .Net 3.1 to .Net6. This app is deployed to azure inside a docker container. However since this change now the app is unresponsive when deployed.

Investigation:

  • When running locally using ISS, the api’s work as expected.
  • When running locally in a docker container, calling the api’s results in a socket hung up error.

Narrowing down and trying different things while running on a local container, I discover the following:

  • When I skip registering IConfiguration to the IServiceCollection, the api’s all work correctly.
  • If I register an IConfiguration with all Config Providers removed. The socket hung up error returns.

And this is where I’m at a loss, it seems strange to me that an unregistered configuration causes different behaviour to an empty configuration. I am also not sure of what configuration might be used by the middleware.

Question:

What is happening here to cause this strange behaviour?

CodePudding user response:

In the end the solution involved adding the following line to our IConfigurationBuilder builder:

builder = builder.AddEnvironmentVariables("ASPNETCORE_");

At the risk of this answer being not up to SO standards, unfortunately I don't know why this fixes the issue, but hopefully this answer will help anyone else that comes across this issue.

I found the following github issue was quite helpful in getting to this solution: https://github.com/dotnet/aspnetcore/issues/30044

  • Related