ASP.NET Core Adding View Parameter Name Path Cannot Be Null Error

Viewed 3523

I'm trying add view to my ASP.NET Core MVC project and I'm getting an error.

The error message is

 There was an error running the selected code generator:
 'Value  cannot be null. 
 Parameter name:path'

The view is going to use for ViewComponent.

My steps are

 Right click -> 
 Add View -> 
 Type View Name -> 
 Uncheck 'Use a Layout Page' -> 
 Template : Empty -> 
 Click Add.

I searched about it but can't find any result.

EDIT :

Here is a Startup.cs

namespace Udemy.MvcWebUI
{
public class Startup
{
    // This method gets called by the runtime. Use this method to add 
    //services to the container.
    // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
    public void ConfigureServices(IServiceCollection services)
    {
        services.AddScoped<IUsersService, UsersManager>();
        services.AddScoped<IUsersDAL, EFUsersDAL>();

        services.AddScoped<IUsersInfoService, UsersInfoManager>();
        services.AddScoped<IUsersInfoDAL, EFUsersInfoDAL>();

        services.AddScoped<IEventTypesService, EventTypesManager>();
        services.AddScoped<IEventTypesDAL, EFEventTypesDAL>();

        services.AddScoped<IEventsService, EventsManager>();
        services.AddScoped<IEventsDAL, EFEventsDAL>();

        services.AddScoped<ICityService, CityManager>();
        services.AddScoped<ICityDAL, EFCityDAL>();

        services.AddScoped<IDistrictService, DistrcitManager>();
        services.AddScoped<IDistrictDAL, EFDistrictDAL>();

        services.AddDbContext<EventContext>(options => options.UseSqlServer(@"Server=localhost\SQLEXPRESS;Database=Events;
                                        User Id=sa;Password=Omurcan.1994;"));

        services.AddMvc();
    }

    // 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();
        }

        app.UseFileServer();
        app.UseNodeModules(env.ContentRootPath);
        app.UseMvcWithDefaultRoute();

        // db tanimi icin
        using (var serviceScope = app.ApplicationServices.GetService<IServiceScopeFactory>().CreateScope())
        {
            var context = serviceScope.ServiceProvider.GetRequiredService<EventContext>();
            context.Database.EnsureCreated();
        }
    }
}
}

How can I fix it ?

Thanks for your help.

2 Answers

May be Microsoft.VisualStudio.Web.CodeGeneration.Design package is missing in your project!

Install the correct version of Microsoft.VisualStudio.Web.CodeGeneration.Design nuget package according to your project .NET Core version.

Then if you recently updated your project to .NET Core 2.1 from any lower version then update your project's packages to latest version also.

Then don't forget to Download the latest stable version (2.1.500) of .NET Core SDK and install on your machine.

Hope your problem will be solved!

I had a similar issue. It is not working for you because your NuGet package manager is not able to download the Microsoft.VisualStudio.Web.CodeGeneration.Design package. This is happening because you are either not connected to the internet or your NuGet is not configured properly.

You have two options:

1. Configure NuGet:

Tools->NuGet Package Manager->Package Manager Settings

Under NuGet Package Manager dropdown, click Package Sources. Click the green plus to add another source. Name it nuget.org, and define the Source as https://api.nuget.org/v3/index.json

Hit Update and then click OK. Next time you try to add a Razor Page the way you were previously doing (by right clicking Pages->Add->Razor Page), it will automatically download the correct package.

2. Add a Razor Page the traditional way

Right click on Pages->Add->New Item->Razor Page

This way does not required the NuGet package specified above.

Related