Question: No suitable 'Program' type for an entry point

Question

No suitable 'Program' type for an entry point

Answers 1
Added at 2016-01-05 16:01
Tags
Question

It seems that a recent update in the nightly RC2 builds has changed the way that programs are started up. Since updating, I'm now presented with an error when running the following command.

// "commands": {
//      "web": "Microsoft.AspNet.Server.Kestrel --server.urls http://localhost:1287"
// }

dnx --watch web

'Microsoft.AspNet.Server.Kestrel' does not contain a 'Program' type suitable for an entry point Stopped listening.

The Startup.cs compiles and has the follow methods.

public class Startup
{
    public void ConfigureServices(IServiceCollection services, IHostingEnvironment env)
    { ... }

    public void Configure(IApplicationBuilder app, IApplicationLifetime lifetime)
    { ... }
}

What needs to be done to get the program to start up with the latest nightly builds?

Here is an example that reproduces the issue. https://github.com/roydukkey/moist/tree/stackoverflow-34615917

sdk: v1.0.0-rc2-16357

Answers to

No suitable 'Program' type for an entry point

nr: #1 dodano: 2016-01-05 17:01

You need to add a static class which has a static Main method in it. From there, you need to host it. Like below:

public class Program
{
    public static void Main(string[] args)
    {
        var configuration = WebApplicationConfiguration.GetDefault(args);

        var application = new WebApplicationBuilder()
                    .UseApplicationBasePath(Directory.GetCurrentDirectory())
                    .UseConfiguration(configuration)
                    .UseStartup<Startup>()
                    .Build();

        application.Run();
    }
}

Not sure if mandatory but you may need to have the below in your project.json as well:

"compilationOptions": {
    "emitEntryPoint": true
}

In full version:

{
    "version": "1.0.0",
    "compilationOptions": {
        "emitEntryPoint": true
    },
    "dependencies": {
        "Microsoft.AspNet.Server.Kestrel": "1.0.0-rc2-*",
        "Microsoft.AspNet.Hosting": "1.0.0-rc2-*"
    },
    "frameworks": {
        "dnx451": {},
        "dnxcore50": {}
    }
}
Source Show
◀ Wstecz