1

In an Azure web role, I want to retrieve the date/time when an assembly was build. I've seen a few tricks to do this by retrieving the linker timestamp from the PE header, but this requires you to read the Assembly.Location which doesn't seem to work in a Azure project. I get this exception:

NotSupportedException - The invoked member is not supported in a dynamic assembly

Perhaps there's a better way of getting this info. Perhaps I can grab the date/time when the Web Role was deployed? That would work for me as well.

Thanks for any help.

Community
  • 1
  • 1
Johan Danforth
  • 4,469
  • 6
  • 37
  • 36

2 Answers2

0

You are asking two separate things. It is very much possible that the time when code was compiled/build could be far different then when the role was deployed. So you may get the same date/time and may not, there is no guarantee unless you control build and deploy same time.

If your objective is to know when the role was deployed, you can add this date/time in multiple location and retrieve it in your Role specific code directly. I am not sure if there is a way to get the deployment time from the role and will look deep later.

Here are few suggestions comes in my mind immediately:

  1. Create a "String" setting in your Service Configuration and read it in your Role specific Code. Keep in mind you can not get Service Configuration settings directly in Web Role specific W3WP.exe process as these two process run separately and need some extra coding.

  2. You can also add Date/Time to service configuration and access either in Startup task to process further as below: http://blogs.msdn.com/b/avkashchauhan/archive/2011/11/09/how-to-access-service-configuration-settings-in-windows-azure-startup-task.aspx

  3. You can add Date/Time setting in your App.Config and access it. I have described here: http://blogs.msdn.com/b/avkashchauhan/archive/2011/10/25/reading-configuration-entries-using-system-configuration-configurationmanager-class-in-a-windows-azure-application.aspx

AvkashChauhan
  • 20,495
  • 3
  • 34
  • 65
  • I'm marking this as the best answer because it answers one of the questions of "other ways to do it". The reason why it didn't work in my case was because I tried to get the location of a web assembly, which doesn't work in this Environment. It works if I check the assembly of a separate "class library" Project. – Johan Danforth Jun 05 '12 at 13:05
0

In the solution you linked to, instead of doing this:

System.Reflection.Assembly assembly = System.Reflection.Assembly.GetExecutingAssembly();

Try doing this:

System.Reflection.Assembly assembly = typeof(AClassInMyAssembly).Assembly;

I'm not sure that will work, but I think it might. If not, you might consider if the Assembly Version would work for your purposes.

Brian Reischl
  • 7,216
  • 2
  • 35
  • 46