error CS0246: The type or namespace name 'UseStartup' could not be found (are you missing a using directive or an assembly reference?) [/home/orly/KeyVaultDemoApp/KeyVaultDemoApp.csproj]

orlyo 0 Reputation points Microsoft Employee
2025-04-22T19:00:41.42+00:00

error CS0246: The type or namespace name 'Startup' could not be found (are you missing a using directive or an assembly reference?) [/home/????/KeyVaultDemoApp/KeyVaultDemoApp.csproj]

This question is related to the following Learning Module

Azure Training
Azure Training
Azure: A cloud computing platform and infrastructure for building, deploying and managing applications and services through a worldwide network of Microsoft-managed datacenters.Training: Instruction to develop new skills.
2,422 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Pradeep M 8,660 Reputation points Microsoft External Staff Moderator
    2025-04-23T04:04:29.02+00:00

    Hi orlyo

    Thank you for reaching out to Microsoft Q & A forum. 

    Thank you for bringing this to our attention. We'll inform the internal team so the exercise can be updated in the future. 

    In the meantime, please update your Program.cs file with the revised code below. This approach eliminates the need for a Startup.cs file and follows the latest ASP.NET Core best practices: 

    using System;
    using Azure.Identity;
    using Microsoft.AspNetCore.Builder;
    using Microsoft.Extensions.Configuration;
    using Microsoft.Extensions.DependencyInjection;
    using Microsoft.Extensions.Hosting;
    var builder = WebApplication.CreateBuilder(args);
    // Load secrets from Azure Key Vault
    var vaultName = builder.Configuration["VaultName"];
    if (!string.IsNullOrEmpty(vaultName))
    {
        var vaultUri = new Uri($"https://{vaultName}.vault.azure.net/");
        builder.Configuration.AddAzureKeyVault(vaultUri, new DefaultAzureCredential());
    }
    // Register services
    builder.Services.AddControllers();
    var app = builder.Build();
    // Configure HTTP request pipeline
    app.MapControllers();
    app.Run();
    
    

    This setup removes the need for a Startup class, follows the latest pattern for ASP.NET Core, and works perfectly with your SecretTestController.cs file. 

    To create the Controllers folder and add the SecretTestController.cs file, run: 

    mkdir Controllers
    touch Controllers/SecretTestController.cs
    
    

    Then, paste the controller code and save.     

    If you have found the answer provided to be helpful, please click on the "Accept answer/Upvote" button so that it is useful for other members in the Microsoft Q&A community.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.