Search code examples
asp.net-mvc-5asp.net-web-api2startup

No assembly found containing a Startup or [AssemblyName].Startup class


I've tried resolving this from answers in other and similar posts, but no luck.
I'm Using MVC 5, framework 4.8 latest VS2017.

Thanks

My Config is: (including other attempts)

<configuration>
    <appSettings>
        <!--<add key="owin:AutomaticAppStartup" value="false" />-->
        <add key="owin:HandleAllRequests" value="true"/>
        <!--<add key="owin:AppStartup" value="Api.xxx" />-->
    </appSettings>
</configuration>

Startup class is:

[assembly: OwinStartupAttribute(typeof(Api.xxx.Startup))]
namespace Api.xxx
{
    public class Startup
    {
        public void Configuration(IAppBuilder app)
        {
            // Allow all origins
            app.UseCors(Microsoft.Owin.Cors.CorsOptions.AllowAll);
            ….
        }
    }
}

and Api is:

namespace Api.xxx
{
    [Route("values")]
    public class ValuesController : ApiController
    {
        private static readonly Random _random = new Random();

        public IEnumerable<string> Get()
        {
            var random = new Random();
            return new[]
            {
                _random.Next(0, 10).ToString(),
                _random.Next(0, 10).ToString()
            };
        }
    }
}

Solution

  • I think you need to change

    [assembly: OwinStartupAttribute(typeof(Api.xxx.Startup))]

    to

    [assembly: OwinStartup(typeof(Api.xxx.Startup))]

    Reference: https://learn.microsoft.com/en-us/aspnet/aspnet/overview/owin-and-katana/owin-startup-class-detection