首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >变量appAssembly = Assembly.GetEntryAssembly();&Assembly.GetEntryAssembly-不混合?

变量appAssembly = Assembly.GetEntryAssembly();&Assembly.GetEntryAssembly-不混合?
EN

Stack Overflow用户
提问于 2016-01-04 21:11:53
回答 1查看 147关注 0票数 2

在我使用OWIN的WebAPI项目中,调用似乎总是返回NULL:

代码语言:javascript
复制
var appAssembly = Assembly.GetEntryAssembly();

我也试过:

代码语言:javascript
复制
var entryAssembly = new StackTrace().GetFrames().Last().GetMethod().Module.Assembly;

返回的只有"System.Web“。

如何捕获应用程序的名称、版本?

我正试图在Web项目的Startup项目中捕捉这些信息:

代码语言:javascript
复制
/// <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.");
    }
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-01-04 21:19:18

使用:

代码语言:javascript
复制
var appAssembly = typeof(Startup).Assembly;
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/34599930

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档