Not picking up ASP.NET application version

Raymond Gunn

Posted on
Aug 08 2015

I'm using Raygun in my ASP.NET application, and I'm specifying my app version in web.config:

  <RaygunSettings apikey="..." excludeErrorsFromLocal="true" applicationVersion="2.31" />

But I'd like to not have to do this. The documentation says Raygun will attempt to send the assembly version of our project with each report, but this isn't working. I have this in AssemblyInfo.cs.

// You can specify all the values or you can default the Revision and Build Numbers 
// by using the '*' as shown below:
[assembly: AssemblyVersion("2.31.*")]
[assembly: AssemblyFileVersion("2.31.0.0")]

Am I doing something wrong, or using the wrong field?


Jamie Penney

Posted on
Aug 10 2015

Hi Raymond,

The ASP.Net library is one of the few places we can't automatically pick up the Version Number unfortunately. If you look at the source here (https://github.com/MindscapeHQ/raygun4net/blob/master/Mindscape.Raygun4Net/RaygunMessageBuilder.cs#L169) you can see we use Assembly.GetEntryAssembly() to get the assembly that your app started in (which is the assembly most likely to have the right Version set). When running under IIS, this returns null.

To get around this, you can set it manually. You need to implement IRaygunApplication on your HttpAPplication (there's more detail here https://github.com/MindscapeHQ/raygun4net#additional-aspnet-configuration-options under "Providing a custom RaygunClient to the http module") and set the ApplicationVersion property on the RaygunClient before returning it. We use the following code to do this:

try
{
    // Attempt to set the version if we can
    client.ApplicationVersion = Assembly.GetExecutingAssembly().GetName().Version.ToString();
}
catch { }

Cheers, Jamie


Reply