Search code examples
.netdockerasp.net-core

Container of ASP.NET Core Web API throws an error 502


On my server I have two containers - one for ASP.NET Core Web API, and another one for SQL Server.

They are working normally and when I want to deploy new image for my Web API, it's stopped suddenly with an understandable error in logs of the container.

Note: I have three containers, dev, qa and staging and the code is the same in each container with just different connection string, so it always works on dev and qa, but it's not working on staging.

Gere are the logs

Unhandled exception. System.ArgumentNullException: Value cannot be null. (Parameter 'value')

at System.ArgumentNullException.Throw(String paramName)
at System.Boolean.Parse(String value)
at Mofleet.Web.Host.Startup.AuthConfigurer.Configure(IServiceCollection services, IConfiguration configuration) in /src/src/Mofleet.Web.Host/Startup/AuthConfigurer.cs:line 17 at Mofleet.Web.Host.Startup.Startup.ConfigureServices(IServiceCollection services) in /src/src/Mofleet.Web.Host/Startup/Startup.cs:line 57 at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor) at System.Reflection.MethodInvoker.Invoke(Object obj, IntPtr* args, BindingFlags invokeAttr) at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) at Microsoft.AspNetCore.Hosting.ConfigureServicesBuilder.InvokeCore(Object instance, IServiceCollection services) at Microsoft.AspNetCore.Hosting.GenericWebHostBuilder.UseStartup(Type startupType, HostBuilderContext context, IServiceCollection services, Object instance) at Microsoft.Extensions.Hosting.HostBuilder.InitializeServiceProvider() at Microsoft.Extensions.Hosting.HostBuilder.Build() at Mofleet.Web.Host.Startup.Program.Main(String[] args) in /src/src/Mofleet.Web.Host/Startup/Program.cs:line 12

Every time this error shows up, I deployed the image again to make it work. Sometimes it needs several deployments to work.


Solution

  • I Solve it by Adding a OnModelCreating and Define decimal Property

    protected override void OnModelCreating(ModelBuilder modelBuilder) {

      // 2. Decimal Property Issues
      modelBuilder.Entity<Code>()
          .Property(c => c.DiscountPercentage)
          .HasColumnType("decimal(18,2)");
    
    
      base.OnModelCreating(modelBuilder);
    

    }