Azure App service for containers error: repository does not exist or may require ‘docker login’

I have configured my ASP.Net Core 2.2 application for continuous build and deploy through Visual Studio 2019. I also see that the image has been build and the deploy successful in Azure DevOps. However in my App service’s application logs, I see the following errors:

2019-07-03 05:44:22.174 ERROR - Pulling docker image productssimplerregistry/simpler.products:5 failed:
2019-07-03 05:44:22.179 INFO  - Pulling image from Docker hub: productssimplerregistry/simpler.products:5
2019-07-03 05:44:23.663 ERROR - DockerApiException: Docker API responded with status code=NotFound, response={"message":"pull access denied for productssimplerregistry/simpler.products, repository does not exist or may require 'docker login'"}
2019-07-03 05:44:26.233 ERROR - Image pull failed: Verify docker image configuration and credentials (if using private repository)

To fix the issue, you should ensure that your application’s pipeline’s Azure Container Registry is the fully qualified name like  productssimplerregistry.containers.azurecr.io instead of just productssimplerregistry.

2019-07-03 19_23_27-Window

Continue Reading

Configuring Serilog SQL server sink logging for ASP.Net Core application

Here are the changes that you need to make in your ASP.Net Core web application to configure Serilog logging with SQL server sink.

a. Install the following libraries from Nuget, using the Nuget Package Manager
Serilog.AspNetCore
Serilog.Extensions.Logging
Serilog.Settings.AppSettings
Serilog.Settings.Configuration
Serilog.Sinks.MSSqlServer

b. Program.cs:


using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Serilog;
using System;
using System.IO;

namespace Scrubber
{
  public class Program
  {
    public static void Main(string[] args)
    {
      var path = Directory.GetCurrentDirectory();
      var environmentName =Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") ?? "Production";

      var configuration = new ConfigurationBuilder()
      .SetBasePath(path)
      .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
      .AddJsonFile($"appsettings.{environmentName}.json", optional: false, reloadOnChange: true)
      .Build();

      Log.Logger = new LoggerConfiguration()
        .Enrich.FromLogContext()
        .ReadFrom.Configuration(configuration)
        .CreateLogger();

      try
      {
        WebHost.CreateDefaultBuilder(args)
          .UseStartup()
          .UseSerilog()
          .Build()
          .Run();
      }
      finally
      {
        Log.CloseAndFlush();
      }
    }
  }
}

AppSettings.json:


{
  "Serilog": {
    "Using": [ "Serilog.Sinks.MSSqlServer" ],
    "MinimumLevel": "Information",
    "WriteTo": [
      {
        "Name": "MSSqlServer",
        "Args": {
          "connectionString": "YourSQLServerConnectionString",
          "tableName": "Logs",
          "autoCreateSqlTable": true
        }
      }
    ]
  }
}
Continue Reading

System.BadImageFormatException: Index not found. (Exception from HRESULT: 0x80131124)

If you get a

An unhandled exception has occurred while executing the request. 
System.BadImageFormatException: Index not found. (Exception from HRESULT: 0x80131124)

error when publishing your website through Visual Studio, a couple of things to check are:

  • When publishing the application to Azure make sure that the “Remove Additional Files at destination” option is checked.

    image
  • Made sure that all the projects(only one) were being build as “Any CPU” in both “debug” and “release” configuration.
    image
Continue Reading

Configuring Azure app services logging for ASP.Net Core application

If you are using Azure to host your ASP.Net Core website and don’t want to spend time configuring logging in your web application, then you can use Azure App services logging. Here are the changes that you need to make in your web application to configure logging.

Startup.cs:


using Microsoft.Extensions.Logging.AzureAppServices;
public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
         services.Configure<AzureFileLoggerOptions>
(Configuration.GetSection("AzureAppServicesLogging"));
} }

AppSettings.json:


{
"AzureAppServicesLogging": {
"BlobName": "Log.txt"
}
}

I have also turned Detailed error messages on, so I can more glean more details if an error occurs.

image

image

Continue Reading

“Client with IP address is not allowed to access the server” when running update-database command through Visual Studio.

If you are deploying your entity framework database changes to your production database through Visual Studio(like we do) for the first time,  you might receive the following error:

Cannot open server '<ServerName>' requested by the login. 
Client with IP address '<MyIPAddress>' is not allowed to access the server.  
To enable access, use the Windows Azure Management Portal or 
run sp_set_firewall_rule on the master database to create a firewall rule for this IP address or address range.  
It may take up to five minutes for this change to take effect.

To fix this issue, you need to go to your database in the azure portal, click “Set server Firewall” and then add your IP address under “Add Client IP”

2019-04-30 23_10_11-SimplerProductsScrubber_db - Microsoft Azure

image

Continue Reading