Resolved Error - No Assembly Found Containing An OwinStartupAttribute No Assembly Found Containing A Startup Or [AssemblyName].Startup class

Background

 
I was developing an MVC web application and I wanted to call the Microsoft Graph API. So, I started from scratch, i.e., created a new MVC application, and used the NuGet Package Manager to install the following required packages.
  1. Install-Package Microsoft.Owin.Host.SystemWeb
  2. Install-Package Microsoft.Owin.Security.OpenIdConnect
  3. Install-Package Microsoft.Owin.Security.OpenIdConnect
  4. Install-Package Microsoft.Owin.Security.Cookies
  5. Install-Package Microsoft.Identity.Client -Version 4.3.1
  6. Install-Package Microsoft.Graph -Version 1.17.0
Those packages are installed successfully. Then, I executed/ran the application, and got the following error.
 
Error – No assembly found containing an OwinStartupAttribute No assembly found containing a Startup or [AssemblyName].Startup class
 
Server Error in ‘/’ Application.
 
The following errors occurred while attempting to load the app.

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

To disable OWIN startup discovery, add the appSetting owin:AutomaticAppStartup with a value of “false” in your web.config.

To specify the OWIN startup Assembly, Class, or Method, add the appSetting owin:AppStartup with the fully qualified startup class or configuration method name in your web.config.

Description

 
An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details
 
System.EntryPointNotFoundException: The following errors occurred while attempting to load the app.

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

To disable OWIN startup discovery, add the appSetting owin:AutomaticAppStartup with a value of “false” in your web.config.

To specify the OWIN startup Assembly, Class, or Method, add the appSetting owin:AppStartup with the fully qualified startup class or configuration method name in your web.config.

Source Error

 
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace: [EntryPointNotFoundException: The following errors occurred while attempting to load the app.

 – No assembly found containing an OwinStartupAttribute.
 – No assembly found containing a Startup or [AssemblyName].Startup class.
To disable OWIN startup discovery, add the appSetting owin:AutomaticAppStartup with a value of “false” in your web.config.

To specify the OWIN startup Assembly, Class, or Method, add the appSetting owin:AppStartup with the fully qualified startup class or configuration method name in your web.config.]

Microsoft.Owin.Host.SystemWeb.OwinBuilder.GetAppStartup() +357
Microsoft.Owin.Host.SystemWeb.OwinHttpModule.InitializeBlueprint() +28
System.Threading.LazyInitializer.EnsureInitializedCore(T& target, Boolean& initialized, Object& syncLock, Func`1 valueFactory) +115
Microsoft.Owin.Host.SystemWeb.OwinHttpModule.Init(HttpApplication context) +106
System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers) +536
System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context) +172
System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) +336
System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) +296
[HttpException (0x80004005): The following errors occurred while attempting to load the app.
 – No assembly found containing an OwinStartupAttribute.
 – No assembly found containing a Startup or [AssemblyName].Startup class.

To disable OWIN startup discovery, add the appSetting owin:AutomaticAppStartup with a value of “false” in your web.config.

To specify the OWIN startup Assembly, Class, or Method, add the appSetting owin:AppStartup with the fully qualified startup class or configuration method name in your web.config.]

System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +9984648
System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +101
 System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +254
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.6.1715.0
 

Solution

 
There are multiple options to solve this issue. If we notice, options are mentioned in stack trace itself, i.e., 
 
To disable OWIN startup discovery, add the appSetting owin:AutomaticAppStartup with a value of “false” in your web.config.
 
To specify the OWIN startup Assembly, Class, or Method, add the appSetting owin:AppStartup with the fully qualified startup class or configuration method name in your web.config.
 
Option 1
 
So if we update the web.config file, add new key “<add key=”owin:AutomaticAppStartup” value=”false” />” in <appSettings> in the <configuration> section.
 
web.config file change for disableing the automatic startup of OWIN
 
Option 2
 
Add default OWIN startup class.
 
 adding default OWIN Startup class in project
  1. public class Startup  
  2.     {  
  3.         public void Configuration(IAppBuilder app)  
  4.         {  
  5. // For more information on how to configure your application,   
  6. //visit https://go.microsoft.com/fwlink/?LinkID=316888  
  7.         }  
  8.     } 
Here, for our solution, we have used the second option.
 
Details
 
As I am a cloud (M365 / SharePoint) guy, I was not much aware of the exact issue so I  thought to go in depth.
 

What is OWIN?

 
OWIN = Open Web Interface for .NET
 
Before OWIN, Microsoft ASP.NET framework was lacking portability, molecularity, and scalability. This means there were still dependencies between Microsoft ASP.NET  applications and hosting servers. So, OWIN came up with the concept of how the dependency between ASP.NET application and hosting servers can be removed.
 
OWIN removes ASP.NET application dependency on System.Web assembly which heavily depends on IIS (webserver). Before OWIN, it's not possible to run the ASP.NET application on a different web server than IIS. OWIN decouples the relationship between ASP.NET application and IIS by defining a standard interface.
 

OWIN Framework

 
Owin Framework is a set of NuGet packages that can be used to build powerful and extremely scalable applications and services that are delivered over HTTP.
 
The Owin framework is built on OWIN, developed by Microsoft to isolate web applications from the hosting platform. This means that applications based on OWIN can run on Apache, IIS, self-host (ie run as a standalone application that listens for HTTP requests directly) or any other hosting platform.
 
I hope this will clear the concept of why OWIN is required here to execute the application as a standalone application by self-hosting ๐Ÿ™‚


Similar Articles