Could not load file or assembly ‘System.Runtime, Version 6.0.0.0’ with .Net Core

Binod Mahto
3 min readAug 12, 2022

--

It’s the story of a couple of days back, where as usual I deployed my application on Azure App Service after testing it locally, and then I was surprised when the application was not running as expected. The experience here was like, “Sometimes truth is not the one which you see”.

Since everything works locally so there was no reason to believe any error in the cloud environment too. So I just do a google search and found a lot of links related to this error but unfortunately none of them related to the problem I had. So with a couple of my cool collogues, I started troubleshooting this issue, and this is what I did until I was able to drill down to the root cause.

  1. Tried to get the actual cause by running the dll from Azure App Service => Console option, and it tells me the error as the title says.

2. Deployment of the application to the Azure App Service was happening through CI/CD pipeline So I thought there could be something wrong with this hence tried the deployment through the visual studio to App Service and modified the appsettings.production.json through App Service => App Service Editor option (at the time of this article this feature is on Preview),
and As a result, it works then what the hell is going wrong with CI/CD deployment, and still no clue.

3. Tried the application for local IIS deployment and it worked here too. Oh my God.

4. After spending hours a random thought occurred, With the working application deployed in local IIS, I replaced the appsetting.Production.json file locally by copying it from Azure App Service => App Service Editor option (to use the one deployed to azure and created by CI/CD process).

Finally, here I got some relief as the issue was reproducible with local env and set up for debugging. While debugging I found that the issue was with the below code throwing an exception due to the key vault URL value being an Empty character.

builder.Configuration.AddAzureKeyVault(
new Uri(keyVaultUrl),
new DefaultAzureCredential(new DefaultAzureCredentialOptions
{
...
}),
new PrefixKeyVaultSecretManager(prefix));

So what was happening here is, In production, the application was not using Azure Key Vault but the code was there, and tried to build the configuration with AzureKeyValut and throwing exceptions.

CI/CD was creating the appSettings.Production.json and in this process, it was replacing the keyvalut-related setting to “ “ an empty character and this was the culprit.

Before I found this issue, it was looking huge but after I found it, I felt like Ahk! what the hell.

So if you ever encountered such errors with production, My first recommendation would be to run the application locally with the same configuration and appsettings.json or web.config used in deployment/production and save your time. Sometimes google also won’t be able to help you unless some people like me share his/her crazy experiences like this.

I had no plan to share this :) until I got the below feedback from one of my readers for a similar crazy issue related to docker networking.

Thank You All for such beautiful feedback which turns into fuel for people like me to share more and more even if it seems to be silly sometime.

Hope you enjoyed the content, follow me for more like this, and please don’t forget to clap for it. Happy programming.

--

--

Binod Mahto

Solution Architect & Full Stack Developer. Passionate about Software designing & development and Learning Technologies and Love to share what I learn.