3

I'm looking into creating a automated way to check the running version of our system(s). Whenever we release code to test we version is using

[assembly: AssemblyVersion("1.21.0.13329")]
[assembly: AssemblyFileVersion("1.21.0.13329")]

I now want to extend our ASP.Net Web forms and Web Services to display this version number. So the Web forms app will put it somewhere on the home page and the web service will probably have a web method that returns the version number.

I was thinking of using

Version version = Assembly.GetExecutingAssembly().GetName().Version;

to do this. But I'm concerned that because this is using reflection it could add a performance overhead to my code. It could be getting called several times, especially on the home page and I don't want this to slow response times down.

I have another solution so I don't want alternatives, I just want to know if anyone knows if the performance overhead of this is going to be relatively significant?

Liam
  • 27,717
  • 28
  • 128
  • 190

1 Answers1

12

The question of the performance overhead and whether it is significant is really dependent on how much it is accessed. On a single page hit, probably not - the code execution time being measured in some ms. If the server is under load with lots of hits, quite possibly.

But can't you just make the hit once anyway (i.e. still use reflection, but not every time):

I'm assuming this won't change over the life of a web application instance - so why not capture this information once and store it?

Perhaps create a class to capture this, such as:

public class AppVersion
{
    private static readonly Version _applicationVersion = Assembly.GetExecutingAssembly().GetName().Version;

    public static Version ApplicationVersion
    {
        get { return _applicationVersion; }
    }
}

You can now access this in code via:

var version = AppVersion.ApplicationVersion
Liam
  • 27,717
  • 28
  • 128
  • 190
Rob Levine
  • 40,328
  • 13
  • 85
  • 111
  • In what circumstances would this re-read the assembly version? When the App Pool is restarted I presume? – Liam Jun 14 '12 at 10:37
  • Yes - exactly. When the AppPool is restarted - and on creation of each new AppDomain within your app. – Rob Levine Jun 14 '12 at 10:38
  • Editied this answer, it was pretty much right but the call to Assembly was wrong, changed in question also – Liam Oct 19 '12 at 12:10