Storing assembly Version readonly
<p>this is a follow on from this question I asked a while ago:</p>

<p><a href="http://stackoverflow.com/questions/11031233/assembly-getentryassembly-performance">Assembly.GetEntryAssembly() performance</a></p>

<p>this solution seemed perfect. Now I've just gottent around to implementing it and it doesn't work. I get a <code>System.TypeInitializationException</code> thrown, the inner exception is the good old, <code>Object reference not set to an instance of an object</code>. Now I'm not sure why it's not working. My guess is that the <code>static readonly</code> property is instanticating before the Assembly class or something? </p>

<p>Can anybody shed any light on <strong>why</strong> this is happening, any fixes, <em>other than not use a readonly as this is obvious</em>, would also be welcome though not necessarily expected!</p>

<p>Here's the code:</p>

<pre><code>public class VersionHelper
    {
        private static readonly Version _applicationVersion = Assembly.GetEntryAssembly().GetName().Version;
        public static string GetVersionText()
        {
            return string.Format("Version: {0}-{1}", _applicationVersion, Environment.MachineName.Substring(5));
        }
    }
</code></pre>

<p>Called:</p>

<pre><code>protected void Page_Load(object sender, EventArgs e)
{
    lblVersion.Text = VersionHelper.GetVersionText();
}
</code></pre>

<p>Just to explain if I do it this way it works:</p>

<pre><code>public class VersionHelper
    {
        public static string GetVersionText()
        {
            Assembly web = Assembly.GetExecutingAssembly();
            AssemblyName webName = web.GetName();
            return string.Format("Version: {0}-{1}", webName.Version, Environment.MachineName.Substring(5));
        }
    }
</code></pre>
