0
votes

I've deployed my API to an Azure App Service and get the error:

The resource you are looking for has been removed,had its name changed,or is temporarily unavailable.

any time I try to hit the endpoint of the only current operation in the API. All of the files have deployed correctly in the wwwroot folder and if I enter url/filename where url is the base url and filename is any of the files in the folder, I am able to download the file. The API works when run locally, hitting the operation returns the expected json result.

Running a trace gives the rather generic result:

System.NullReferenceException 2 Object reference not set to an instance of an object. Stack Trace 1 mscorlib!System.Diagnostics.Tracing.EventSource.SendCommand mscorlib!System.Diagnostics.Tracing.EventSource+OverideEventProvider.OnControllerCommand mscorlib!System.Diagnostics.Tracing.EventProvider.EtwEnableCallBack mscorlib!dynamicClass.IL_STUB_ReversePInvoke

The routes are configured correctly (in that it works locally) - the error implies that a related file is missing, however checking the folder in Kudu shows the files match the contents of the bin folder. Any ideas on what is going wrong here? Or how to determine what the missing resource is? Thanks for reading.

public class Startup
{
    public Startup(IConfiguration configuration)
    {
        Configuration = configuration;
    }

    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.AddControllers();
        services.AddLogging(logging =>
        {
            logging.AddConsole();
            logging.AddDebug();
        });
        services.AddDbContext<hidden>(options => options.UseSqlServer(Configuration.GetConnectionString("hidden")));
        services.AddScoped<DbContext, hidden>();
        services.AddScoped(typeof(IQuery<>), typeof(NoTrackingQuery<>));
        services.AddScoped(typeof(IQuery<,>), typeof(NoTrackingQuery<,>));
        services.AddSwaggerGen(c =>
        {
            c.SwaggerDoc("v1", new OpenApiInfo { Title = "Hidden", Version = "v1" });
        });
    }

    // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
    public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
    {
        // Expose logging where DI cannot be used
        var loggerFactory = app.ApplicationServices.GetRequiredService<ILoggerFactory>();
        LogManager.SetLogger(loggerFactory);

        if (env.IsDevelopment())
        {
            app.UseDeveloperExceptionPage();
            app.UseSwagger();
            app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "Hidden v1"));
        }

        app.UseHttpsRedirection();

        app.UseRouting();

        app.UseAuthorization();

        app.UseEndpoints(endpoints =>
        {
            endpoints.MapControllers();
        });
    }
}

  [ApiController]
[Route("[controller]")]
public class WidgetController : ControllerBase
{
    private readonly IQuery<Category> _categories;

    public WidgetController(IQuery<Widget> widgets)
    {
        _widgets = widgets;
    }

    [HttpGet]
    public IEnumerable<Widget> Get()
    {
        return _widgets.QueryAll();
    }
}
2

2 Answers

0
votes

When you can run a solution locally, and not able to run it on Cloud, it means that you have misconfigured something.

Looking at the error message I suspect that the settings for Logging are not in place. Make sure that you put all required/consumed settings in Application Settings or Connection Strings.

0
votes

Thanks singhh-msft. You were right and this was caused by using the incorrect publish task in the build pipeline. Updated to use dotnet Azure CLI publish command and the issue is resolved.