Keith Barrows
Keith Barrows

Reputation: 25308

var appAssembly = Assembly.GetEntryAssembly(); & OWN - don't mix?

It seems, in my WebAPI project, which uses OWIN, the call always returns NULL:

var appAssembly = Assembly.GetEntryAssembly();

I've also tried:

var entryAssembly = new StackTrace().GetFrames().Last().GetMethod().Module.Assembly;

All that returns is "System.Web".

How do you capture the App Name, Version???

I am trying to capture this information right at Startup for the Web API project:

/// <summary>
/// The OWIN startup class.
/// </summary>
public class Startup
{
    /// <summary>
    /// The necessary OWIN configuration method.
    /// </summary>
    /// <param name="app">The app being started under OWIN hosting.</param>
    public void Configuration(IAppBuilder app)
    {
        var appAssembly = Assembly.GetEntryAssembly();
        Aspect.Logging.LoggingHandler.Initialize(appAssembly, "Hard Coded App Name!");
        Log.Information("Starting App...");

        // Order is important here. The security wiring must happen first.
        ConfigureAuthentication(app);

        // Create web configuration and register with WebAPI.
        HttpConfiguration config = new HttpConfiguration();
        WebApiConfig.Register(config);

        // Configure documentation.
        ConfigureDocumentation(config);

        // Configure support for static files (e.g. index.html).
        app.UseFileServer(new FileServerOptions
        {
            EnableDefaultFiles = true,
            FileSystem = new PhysicalFileSystem(".")
        });


        // Start the API.
        app.UseWebApi(config);
        Log.Information("App started.");
    }

Upvotes: 2

Views: 164

Answers (1)

vcsjones
vcsjones

Reputation: 141668

Use:

var appAssembly = typeof(Startup).Assembly;

Upvotes: 3

Related Questions