Skip to content
This repository was archived by the owner on Dec 19, 2018. It is now read-only.
This repository was archived by the owner on Dec 19, 2018. It is now read-only.

Moving Startup class to a library project breaks my site. #903

@Eilon

Description

@Eilon

From @sam-wheat on December 19, 2016 21:43

This question refers to beta I am using .net core 1.1:
http://stackoverflow.com/questions/33183357/move-startup-cs-to-class-library-package-project-asp-net-5

I moved my Startup class to a library project and now my site does not work. Only error I get is 404.
I checked ContentRootPath and it appears to point to the correct directory.
I see no errors in the output window.
IIS Express says my site is running on the correct port specified in launchSettings.json.
Startup class is exactly the same in library project as site project. Only difference is namespsce.
I don't believe my question is environment related:
https://docs.microsoft.com/en-us/aspnet/core/fundamentals/startup?highlight=startup#the-startup-class

Program.cs:

public static void Main(string[] args)
    {
        var host = new WebHostBuilder()
            .UseKestrel()
            .UseContentRoot(Directory.GetCurrentDirectory())
            .UseIISIntegration()
            //.UseStartup<xStartup>() works
            .UseStartup<Application.AppComponents.Startup>() // broken
            .Build();

        host.Run();
    }

Startup.cs (exactly the same in library / application projects):

public class Startup
{
    public Startup(IHostingEnvironment env)
    {
        
        var builder = new ConfigurationBuilder()
            .SetBasePath(env.ContentRootPath)
            .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
            .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
            .AddEnvironmentVariables();
        Configuration = builder.Build();
    }

    public IConfigurationRoot Configuration { get; }

    // This method gets called by the runtime. Use this method to add services to the container.
    public IServiceProvider ConfigureServices(IServiceCollection services)
    {
        // Add framework services.
        services.AddMvc();
        // Autofac

        ContainerBuilder builder = new ContainerBuilder();
        builder.RegisterModule(new Application.AppComponents.IOCModule());

        builder.Populate(services);
        var container = builder.Build();
        return container.Resolve<IServiceProvider>();
    }

    // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
    public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
    {
        loggerFactory.AddConsole(Configuration.GetSection("Logging"));
        loggerFactory.AddDebug();

        app.UseMvc();
    }
}

Copied from original issue: aspnet/Mvc#5623

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions