title: System.ArgumentNullException: String reference not set to an instance of a String. Parameter name: s
body: <p>Unable to Identify the error after publishing the file </p>
  
  <p><strong>at System.Text.Encoding.GetBytes(String s)
     at Inspection.Apis.Startup.ConfigureServices(IServiceCollection services) in C:\Users\me_mo\source\InspectionBackend\Inspection.Apis\Startup.cs:line 66</strong></p>
  
  <p>Line 66 is Swagger configuration</p>
  
  <p>I tried to run also on release mode and its running fine.</p>
  
  <p>Finding out this error just on deployment </p>
  
  <pre><code> namespace Inspection.Apis
   {
   public class Startup
   {
       public Startup(IHostingEnvironment environment, IConfiguration configuration)
       {
           Environment = environment;
           Configuration = configuration;
       }
       public IHostingEnvironment Environment { get; }
  
       public IConfiguration Configuration { get; }
  
       // This method gets called by the runtime. Use this method to add services to the container.
       public void ConfigureServices(IServiceCollection services)
       {
           services.AddAutoMapper(typeof(AutoMapperMappings).Assembly);
           services.AddDbContext&lt;InspectionEfContext, InspectionContext&gt;();
           services.AddDbContext&lt;InspectionContext&gt;();
           services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
           services.AddHttpContextAccessor();
           services.AddCors(options =&gt;
           {
               options.AddPolicy("AllowAll",
                   builder =&gt;
                   {
                       builder
                       .AllowAnyOrigin()
                       .AllowAnyMethod()
                       .AllowAnyHeader()
                       .AllowCredentials();
                   });
           });
           EntityFrameworkManager.ContextFactory = context =&gt;
           {
               return new InspectionContext((context as InspectionContext).RequestInfo);
           };
           services.AddSwaggerGen(options =&gt;
           {
               options.SwaggerDoc("v1", new OpenApiInfo { Title = "Inspection Suite API", Version = "v1" });
               options.OperationFilter&lt;TenantParameterOperationFilter&gt;();
  
  
               options.AddSecurityDefinition("Bearer",
                   new OpenApiSecurityScheme
                   {
                       Description = "JWT Authorization header using the Bearer scheme. \r\n\r\n Enter 'Bearer' [space] and then your token in the text input below.\r\n\r\nExample: \"Bearer 12345abcdef\"",
                       Name = "Authorization",
                       In = ParameterLocation.Header,
                       Type = SecuritySchemeType.ApiKey,
                       Scheme = "Bearer"
                   });
               options.AddSecurityRequirement(new OpenApiSecurityRequirement {
                       {
                           new OpenApiSecurityScheme
                           {
                               Reference = new OpenApiReference
                               {
                                   Type = ReferenceType.SecurityScheme,
                                   Id = "Bearer"
                               },
                               Scheme = "oauth2",
                               Name = "Bearer",
                               In = ParameterLocation.Header,
  
                           },
                           new List&lt;string&gt;() }
                   });
           });
  
  
                 #region JWT
           var key = Encoding.ASCII.GetBytes(Configuration["JwtKey"]);
           services.AddAuthentication(x =&gt;
           {
               x.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
               x.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
           })
           .AddJwtBearer(x =&gt;
           {
               x.RequireHttpsMetadata = false;
               x.SaveToken = true;
               x.TokenValidationParameters = new TokenValidationParameters
               {
                   ValidateIssuerSigningKey = true,
                   IssuerSigningKey = new SymmetricSecurityKey(key),
                   ValidateIssuer = false,
                   ValidateAudience = false
               };
           });
           #endregion
  
  
           services.AddMvc().AddJsonOptions(options =&gt;
           {
               options.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
  
               if (Environment.IsProduction())
               {
                   options.SerializerSettings.NullValueHandling = NullValueHandling.Ignore;
                   options.SerializerSettings.DefaultValueHandling = DefaultValueHandling.Ignore;
               }
           });
  
  
  
           services.AddScoped&lt;IRequestInfo&gt;(provider =&gt;
           {
               var context = provider.GetRequiredService&lt;IHttpContextAccessor&gt;();
               var claims = context.HttpContext.User.Claims;
  
               return new RequestInfo(this.Configuration, int.TryParse(claims.FirstOrDefault(o =&gt; o.Type == "tenantId")?.Value, out int tenantId) ? (int?)tenantId : null);
           });
           services.AddScoped&lt;RequestScope&lt;InspectionContext&gt;&gt;(provider =&gt;
           {
               var dbContext = provider.GetRequiredService&lt;InspectionContext&gt;();
               var scope = provider.GetRequiredService&lt;RequestScope&gt;();
               var userId = provider.GetRequiredService&lt;IHttpContextAccessor&gt;().HttpContext.User.FindFirst(x =&gt; x.Type == "UserId")?.Value;
               return new RequestScope&lt;InspectionContext&gt;(scope.ServiceProvider, dbContext, scope.Logger, scope.Mapper, userId, scope.TenantId);
           });
           services.AddScoped&lt;RequestScope&lt;InspectionEfContext&gt;&gt;(provider =&gt;
           {
               var dbContext = provider.GetRequiredService&lt;InspectionEfContext&gt;();
               var scope = provider.GetRequiredService&lt;RequestScope&gt;();
               var userId = provider.GetRequiredService&lt;IHttpContextAccessor&gt;().HttpContext.User.FindFirst(x =&gt; x.Type == "UserId")?. Value;
               return new RequestScope&lt;InspectionEfContext&gt;(scope.ServiceProvider, dbContext, scope.Logger, scope.Mapper, userId, scope.TenantId);
           });
           services.AddScoped&lt;RequestScope&gt;(provider =&gt;
           {
               var logger = provider.GetRequiredService&lt;ILogger&lt;Program&gt;&gt;();
               var context = provider.GetRequiredService&lt;IHttpContextAccessor&gt;();
               var claims = context.HttpContext.User.Claims;
               var userId = claims.FirstOrDefault(o =&gt; o.Type == "UserId")?.Value;
               var tenantId = int.TryParse(claims.FirstOrDefault(o =&gt; o.Type == "tenantId")?.Value, out int t) ? t : default(int?);
               if (!tenantId.HasValue)
               {
                   tenantId = int.TryParse(context.HttpContext.Request.Headers["tenantId"].SingleOrDefault(), out t) ? t : default(int?);
               }
               var mapper = provider.GetRequiredService&lt;IMapper&gt;();
  
               return new RequestScope(provider, logger, mapper, userId, tenantId);
           });
           ConfigureRepositories(services);
           ConfigureAppServices(services);
       }
       private void ConfigureRepositories(IServiceCollection services)
       {
           services.AddScoped&lt;IUserRepository, UserRepository&gt;();
           services.AddScoped&lt;IFormBuilderTypeRepository, FormBuilderTypeRepository&gt;();
           services.AddScoped&lt;IFormBuilderRepository, FormBuilderRepository&gt;();
           services.AddScoped&lt;IFormBuilderQuestionsRepository, FormBuilderQuestionsRepository&gt;();
           services.AddScoped&lt;IFormBuilderQuestionsResponseRepository, FormBuilderQuestionsResponseRepository&gt;();
       }
       private void ConfigureAppServices(IServiceCollection services)
       {
           services.AddScoped&lt;IUserService, UserServices&gt;();
           services.AddScoped&lt;IAuthenticationService, AuthenticationService&gt;();
           services.AddScoped&lt;UserIdGenerator&gt;();
  
           services.AddScoped&lt;IFormBuilderTypeServices, FormBuilderTypeServices&gt;();
  
           services.AddScoped&lt;IFormBuilderServices, FormBuilderServices&gt;();
           services.AddScoped&lt;IFormBuilderQuestionsServices, FormBuilderQuestionsServices&gt;();
           services.AddScoped&lt;IFormBuilderQuestionsResponseServices, FormBuilderQuestionsResponseServices&gt;();
  
       }
  
  
  
       // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
       public void Configure(IApplicationBuilder app, IHostingEnvironment env)
       {
           if (env.IsDevelopment())
           {
               app.UseDeveloperExceptionPage();
           }
           else
           {
               // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
               app.UseHsts();
           }
           app.UseMiddleware&lt;InspectionExceptionMiddleware&gt;();
           app.UseHttpsRedirection();
           app.UseForwardedHeaders(new ForwardedHeadersOptions
           {
               ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto
           });
           app.UseCors("AllowAll");
           app.UseAuthentication();
           app.UseHttpsRedirection();
           app.UseSwagger();
           app.UseSwaggerUI(c =&gt;
           {
               c.SwaggerEndpoint("/swagger/v1/swagger.json", "Inspection API V1");
               c.RoutePrefix = string.Empty;
           });
  
           app.UseMvc();
       }
   }
   public class TenantParameterOperationFilter : IOperationFilter
   {
       public void Apply(OpenApiOperation operation, OperationFilterContext context)
       {
           if (operation.Parameters == null)
               operation.Parameters = new List&lt;OpenApiParameter&gt;();
  
           operation.Parameters.Add(new OpenApiParameter
           {
               Name = "tenantId",
               In = ParameterLocation.Header,
               Description = "Tenant Id"
           });
       }
   }
  }
  </code></pre>