Genius DM

No assembly found containing an OwinStartupAttribute. 본문

.NET

No assembly found containing an OwinStartupAttribute.

Damon Jung 2017. 11. 29. 13:01

No assembly found containing an OwinStartupAttribute.


IdentityServer3 를 Github Documentation 및 Manual 을 참고하며 구성하는 도중, 첫 번째 IdentityServer3 구동 여부를 확인하는 순간에 아래와 같은 에러를 맞이 했다. 웹 프로젝트를 비교적 오랜만에 해보는 관계로 적지 않게 당황하였는데, 아래에서 중요한 에러 메시지는


		[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) +173
   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) +10085804
   System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +95
   System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +254
	


이것이다.


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


Startup 클래스에 Owin 관련 어셈블리가 없다는 것이다. 안타깝게도 IdentityServer3 안내 페이지에는 아래 코드밖에 안 나와있다.



public class Startup
{
    public void Configuration(IAppBuilder app)
    {
        app.Map("/identity", idsrvApp =>
            {
                idsrvApp.UseIdentityServer(new IdentityServerOptions
                {
                    SiteName = "Embedded IdentityServer",
                    SigningCertificate = LoadCertificate(),

                    Factory = new IdentityServerServiceFactory()
                                .UseInMemoryUsers(Users.Get())
                                .UseInMemoryClients(Clients.Get())
                                .UseInMemoryScopes(StandardScopes.All)
                });
            });
    }

    X509Certificate2 LoadCertificate()
    {
        return new X509Certificate2(
            string.Format(@"{0}\bin\identityServer\idsrv3test.pfx", AppDomain.CurrentDomain.BaseDirectory), "idsrv3test");
    }
}

출처 : https://identityserver.github.io/Documentation/docsv2/overview/mvcGettingStarted.html



이것만 보고 그대로 따라하면, 저 에러를 100% 맞이하게 될 것이다... 해당 GettingStarted 페이지에는 이 어셈블리를 Startup 클래스 파일 상단에 추가하라는 안내도 없다. 너무 쉬운 에러라서 개발자들이 알아서 해결할 것이라 생각했나보다. 

어쨌든 해결 방법은 이것이다.


해결

[assembly: OwinStartup(typeof(YourNamespace.Startup))]

namespace YourProjectNamespace . . . public class Startup { public void Configuration(IAppBuilder app) { app.Map("/identity", idsrvApp => { idsrvApp.UseIdentityServer(new IdentityServerOptions { SiteName = "Embedded IdentityServer", SigningCertificate = LoadCertificate(), Factory = new IdentityServerServiceFactory() .UseInMemoryUsers(Users.Get()) .UseInMemoryClients(Clients.Get()) .UseInMemoryScopes(StandardScopes.All) }); }); } X509Certificate2 LoadCertificate() { return new X509Certificate2( string.Format(@"{0}\bin\identityServer\idsrv3test.pfx", AppDomain.CurrentDomain.BaseDirectory), "idsrv3test"); } }


Startup 클래스의 Namespace 상단에 어셈블리 어노테이션을 추가하면 해결 된다...

참고로 Microsoft.Owin 어셈블리 추가되어 있어야 해당 OwinStartup 생성자를 Assembly 어노테이션 내부에서 사용할 수 있다.

빌드 후 브라우저에서 정상적으로 실행될 것이다.










No assembly found containing an OwinStartupAttribute.


While I'm trying to deploy the IdentityServer3 by looking at its Github documentation and manual, I encountered this error at the first trial to run the server. It's been a while since I tweak some codes on a web project, I was a bit frustrated by this error. Things to notice from the error logs below...


[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) +173
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) +10085804
System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +95
System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +254


are these two lines.


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


It literally says that there's no assembly found on the Startup class, that is related to Owin. Unfortunately there's no further information about this error in the github GettingStarted section. It just shows us this block of codes below.


public class Startup
{
    public void Configuration(IAppBuilder app)
    {
        app.Map("/identity", idsrvApp =>
            {
                idsrvApp.UseIdentityServer(new IdentityServerOptions
                {
                    SiteName = "Embedded IdentityServer",
                    SigningCertificate = LoadCertificate(),

                    Factory = new IdentityServerServiceFactory()
                                .UseInMemoryUsers(Users.Get())
                                .UseInMemoryClients(Clients.Get())
                                .UseInMemoryScopes(StandardScopes.All)
                });
            });
    }

    X509Certificate2 LoadCertificate()
    {
        return new X509Certificate2(
            string.Format(@"{0}\bin\identityServer\idsrv3test.pfx", AppDomain.CurrentDomain.BaseDirectory), "idsrv3test");
    }
}



From : https://identityserver.github.io/Documentation/docsv2/overview/mvcGettingStarted.html



So if you just stick to this code, you're doomed to see the error for sure. No help is provided in the GettingStarted section for that error. Maybe it's so easy and so basic that they would have decided to skip some help tips, thinking developers would get through with it.

Anyway, this is the solution for this.


Solution

[assembly: OwinStartup(typeof(YourNamespace.Startup))]

namespace YourProjectNamespace . . . public class Startup { public void Configuration(IAppBuilder app) { app.Map("/identity", idsrvApp => { idsrvApp.UseIdentityServer(new IdentityServerOptions { SiteName = "Embedded IdentityServer", SigningCertificate = LoadCertificate(), Factory = new IdentityServerServiceFactory() .UseInMemoryUsers(Users.Get()) .UseInMemoryClients(Clients.Get()) .UseInMemoryScopes(StandardScopes.All) }); }); } X509Certificate2 LoadCertificate() { return new X509Certificate2( string.Format(@"{0}\bin\identityServer\idsrv3test.pfx", AppDomain.CurrentDomain.BaseDirectory), "idsrv3test"); } }


Just attach the assembly annotation above the namespace of the startup class.

FYI, it's Microsoft.Owin assembly that let you use OwinStartup constructor in there.

You will see a proper web page after build your project.



































Comments