简体   繁体   中英

ASP.NET Core 2.0 Value cannot be null. Parameter name: Name

I'm trying to host a ASP.NET Core 2.0 WebApplication in local IIS, but evertime i get the following error: Value cannot be null. Parameter name: name

在此处输入图片说明

The launchSettings.json file looks like this:

{
"iisSettings": {
    "windowsAuthentication": false,
    "anonymousAuthentication": true,
    "iis": {
        "applicationUrl": "http://localhost/zoyotravel",
        "sslPort": 0
    },
    "iisExpress": {
        "applicationUrl": "http://localhost:56472/",
        "sslPort": 0
    }
},
"profiles": {
    "IIS Express": {
        "commandName": "IISExpress",
        "launchBrowser": true,
        "environmentVariables": {
            "ASPNETCORE_ENVIRONMENT": "Development"
        }
    },
    "Zoyo Travel": {
        "commandName": "IIS",
        "launchBrowser": true,
        "environmentVariables": {
            "ASPNETCORE_ENVIRONMENT": "Development"
        },
        "applicationUrl": "http://localhost:56473/"
    }
}
}

The program class looks liks this:

public class Program
{
    public static void Main(string[] args)
    {
        BuildWebHost(args).Run();
    }

    public static IWebHost BuildWebHost(string[] args) =>
        WebHost.CreateDefaultBuilder(args)
            .UseStartup<Startup>()
            .Build();
}

The startup class looks like this:

public class Startup
{
    // This method gets called by the runtime. Use this method to add services to the container.
    public void ConfigureServices(IServiceCollection services)
    {
        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.UseWebpackDevMiddleware(new WebpackDevMiddlewareOptions
            {
                HotModuleReplacement = true
            });
        }
        else
        {
            app.UseExceptionHandler("/Home/Error");
        }

        app.UseStaticFiles();

        app.UseMvc(routes =>
        {
            routes.MapRoute(
                name: "default",
                template: "{controller=Home}/{action=Index}/{id?}");

            routes.MapSpaFallbackRoute(
                name: "spa-fallback",
                defaults: new { controller = "Home", action = "Index" });
        });
    }
}

What have I tried so far?

  • I have searched for all the parameters called "name" in the solution. But I could not find anything that could be empty.
  • If I host the website in IIS express then it works.

The problem does not appear to be in the code. It is also a standard asp.net core 2.0 web application. I did not touch the code itself. I have only tried to host the website in IIS.

Can somebody help me?

I have encountered the same issue several times now. Initially I taught I was somehow messing something up because first time I started the app everything worked, but after a restart that "Value cannot be null. Parameter name: name" error appeared again. After some more experimenting with IIS I've discovered that creating and registering your app to a new application pool with the exact same specs, fallowed by iisreset solves this problem. The downside is that you have to do this whenever this error appears. After doing this once just switching between the two pools I now had and iisreset was enough. Hope it helps!

I had the same issue. I spent half a day trying every possible thing that I could think of.

Finally, I figured that

it was an issue with appsettings.json nesting .

I had to remove an extra } from the json file .

Since I cannot see your appsetting.json file here, it may be the problem in your case as well. Hope this helps.

I faced the same issue while doing a Debug (F5).

Solved it as follows:

  1. Set your IIS Site App Pool to DefaultAppPool
  2. Run (F5)
  3. Revert to the actual app pool

In my case issue was about 'uriString'. I don't know why but closing visual studio and opening fixed the issue. I hope it helps someone.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM