Where to implement startup code in VB.Net project?


I’ve just started to integrate Hangfire into an existing ASP.Net VB project. I’ve got most of the code converted from c# and usable, but I’m not sure where to put the code that would normally go into startup.cs.

Also, my project uses ASP forms authentication, so I’m not sure how to configure the OWIN portions of the dashboard.

Currently, my project is showing this error:

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.

Thanks in advance for your help!


Oh! I think I’ve got it figured out… I just created a new class file in App_Code called Startup.vb, and then I used the code from this post, with one fix: Using hangfire in Vb.net

The fixed code is posted below:

Public Sub Configuration(app As IAppBuilder)
    Dim options = New DashboardOptions With {.AppPath = VirtualPathUtility.ToAbsolute("~")}
    app.UseHangfireDashboard("/hangfire", options)
End Sub

Hope somebody finds this useful!

Thanks. That actually worked. What I cannot seem to do is keep it alive. Even with the AppPool “alwaysrunning” it dies and won’t run overnight. Have you managed to get this to function in production?

No, how about you? I could really use it right about now.