Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3849058
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T16:47:46+00:00 2026-05-19T16:47:46+00:00

How do I obtain the version number of the calling web application in a

  • 0

How do I obtain the version number of the calling web application in a referenced assembly?

I’ve tried using System.Reflection.Assembly.GetCallingAssembly().GetName() but it just gives me the dynamically compiled assembly (returning a version number of 0.0.0.0).

UPDATE: In my case I needed a solution that did not require a reference back to a class within the web application assembly. Jason’s answer below (marked as accepted) fulfils this requirement – a lot of others submitted here don’t.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T16:47:47+00:00Added an answer on May 19, 2026 at 4:47 pm

    Here is some code I use that supports getting the application’s “main” assembly from either Web or non-web apps, you can then use GetName().Version to get the version.

    It first tries GetEntryAssembly() for non-web apps. This returns null under ASP.NET.
    It then looks at HttpContext.Current to determine if this is a web application. It then uses the Type of the current HttpHandler – but this type’s assembly might be a generated ASP.NET assembly if the call is made from with an ASPX page, so it traverses the HttpHandler’s BaseType chain until it finds a type that isn’t in the namespace that ASP.NET uses for its generated types (“ASP”).
    This will usually be a type in your main assembly (eg. The Page in your code-behind file). We can then use the Assembly of that Type.
    If all else fails then fall back to GetExecutingAssembly().

    There are still potential problems with this approach but it works in our applications.

        private const string AspNetNamespace = "ASP";
    
        private static Assembly getApplicationAssembly()
        {
            // Try the EntryAssembly, this doesn't work for ASP.NET classic pipeline (untested on integrated)
            Assembly ass = Assembly.GetEntryAssembly();
    
            // Look for web application assembly
            HttpContext ctx = HttpContext.Current;
            if (ctx != null)
                ass = getWebApplicationAssembly(ctx);
    
            // Fallback to executing assembly
            return ass ?? (Assembly.GetExecutingAssembly());
        }
    
        private static Assembly getWebApplicationAssembly(HttpContext context)
        {
            Guard.AgainstNullArgument(context);
    
            object app = context.ApplicationInstance;
            if (app == null) return null;
    
            Type type = app.GetType();
            while (type != null && type != typeof(object) && type.Namespace == AspNetNamespace)
                type = type.BaseType;
    
            return type.Assembly;
        }
    

    UPDATE:
    I’ve rolled this code up into a small project on GitHub and NuGet.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How do I obtain the serial number of the installed Vista system? Also is
Apparently you can easily obtain a client IP address in WCF 3.5 but not
How can I obtain the .NET Framework directory path inside my C# application? The
How can I obtain the command line arguments of another process? Using static functions
How can you obtain the Type (the name as a string is sufficient) of
Where can I obtain the SQL Server Express 64 bit prerequisite to include in
How to obtain Vista Edition programmatically, that is Home Basic, Home Premium, Business or
I want to obtain maximum performance out of a process with many variables, many
currently i obtain the below result from the following C# line of code when
How do you programmatically obtain a picture of a .Net control?

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.