Error (active) CS1061 'WebApplication' does not contain a definition for 'MapStaticAssets' and no accessible extension method 'MapStaticAssets' accepting a first argument of type 'WebApplication' could be found (are you missing a using directive or an assembly reference?)
For this error, it does not relate the seed method. It might relate that you didn't add the.NET 9 SDK and Runtime in your computer.
So, you can check and try the following:
- Use the latest version Visual Studio and install the .NET 9.0 Runtime (via Visual Studio Installer)
- Check the project file, make sure you are using the
.net9.0
TargetFramework, and upgrade the related package to 9.0 version. - Open the project root folder, delete the bin and obj folder, and then rebuild the application.
Besides, when using MapStaticAssets
, refer to the following code:
Finally, if still not working, try to create a new .NET 9 MVC application and check whether it works or not.
In my application, the Program.cs
file like this:
using Microsoft.AspNetCore.Identity;
using Microsoft.EntityFrameworkCore;
using Net9MVCSample.Data;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
var connectionString = builder.Configuration.GetConnectionString("DefaultConnection") ?? throw new InvalidOperationException("Connection string 'DefaultConnection' not found.");
builder.Services.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlServer(connectionString));
builder.Services.AddDatabaseDeveloperPageExceptionFilter();
builder.Services.AddDefaultIdentity<IdentityUser>(options => options.SignIn.RequireConfirmedAccount = true)
.AddEntityFrameworkStores<ApplicationDbContext>();
builder.Services.AddControllersWithViews();
var app = builder.Build();
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseMigrationsEndPoint();
}
else
{
app.UseExceptionHandler("/Home/Error");
// 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.UseHttpsRedirection();
app.UseRouting();
app.UseAuthorization();
app.MapStaticAssets();
app.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}")
.WithStaticAssets();
app.MapRazorPages()
.WithStaticAssets();
app.Run();
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
Best regards,
Dillion