System.Reflection.Assembly.GetExecutingAssembly()

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Has been trying to get an ASP.NET DLL's modification date/time for the
"release date/time" to be displayed on the page's footer

Using:
System.Reflection.Assembly
asm=System.Reflection.Assembly.GetExecutingAssembly();
appVer = asm.GetName().Version.ToString();

// get the location of our executing assembly
System.IO.FileInfo inf = new System.IO.FileInfo(asm.Location);
DateTime dt = inf.LastWriteTime;
appDate = dt.ToString("d MMM yyyy")

log.Info ("asm.Location=" + asm.Location);


However, the debug log indicate that it is reading the last write time from
c:\winnt\microsoft.net\framework\v1.1.4322\temporary asp.net
files\MyProd\0bb3e1a5\e740ffe2\assembly\dl2\a5a61754\024e623d_c70bc601\MyCompany.MyDept.MyProd.dll and not c\inetpub\wwwroot\MyProd\bin\MyProd.dll

How can I update my code to read the last modification date/time of where
the DLL was deployed?

Note the
1) Problem happens both on IIS5.1 / Win XP Pro SP2 and IIS6 / Windows 2003
server
2) .Net framework 1.1
3) Impersonation is used, impersonating the logged on user (no admin
priviledges)
 
Hi,

welcome to MSDN newsgroup.
As for the getting assembly path problem, it is the expected behavior
because:

1. ASP.NET application will always shadow copy all the private
assemblies(in bin dir) to the temporary ASPNET folder......

2. And the Assembly.Location point to the assembly's location after it has
been shadow copied.....

For your scenario, you want to get the assembly's original file path (in
the application's private bin dir), I think you can consider:

1. Using the Assembly.CodeBase instead of the Assembly.Location , CodeBase
point to the original path before shadow copied. here is the MSDN document
on this:
=============
The location of the loaded file that contains the manifest. If the loaded
file was shadow-copied, the location is that of the file after being
shadow-copied. If the assembly is loaded from a byte array, such as when
using the Load(Byte[]) method overload, the value returned is an empty
string ("").
Remarks
To get the location before the file has been shadow-copied, use the
CodeBase property
=============

2. Also, if the assembly's file name is fixed, we can using the
Server.MapPath("~/bin") to get the private bin dir's file path and
concatenate with the assembly file name to get the full file path.....

Hope helps. Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)



--------------------
| Thread-Topic: System.Reflection.Assembly.GetExecutingAssembly()
| thread-index: AcYLyHaN2xw0eoxTSY2durKc+OoAjw==
| X-WBNR-Posting-Host: 198.240.128.75
| From: "=?Utf-8?B?UGF0cmljaw==?=" <[email protected]>
| Subject: System.Reflection.Assembly.GetExecutingAssembly()
| Date: Wed, 28 Dec 2005 08:05:03 -0800
| Lines: 30
| Message-ID: <[email protected]>
| MIME-Version: 1.0
| Content-Type: text/plain;
| charset="Utf-8"
| Content-Transfer-Encoding: 7bit
| X-Newsreader: Microsoft CDO for Windows 2000
| Content-Class: urn:content-classes:message
| Importance: normal
| Priority: normal
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
| Newsgroups: microsoft.public.dotnet.general
| NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.2.250
| Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGXA03.phx.gbl
| Xref: TK2MSFTNGXA02.phx.gbl microsoft.public.dotnet.general:185171
| X-Tomcat-NG: microsoft.public.dotnet.general
|
| Has been trying to get an ASP.NET DLL's modification date/time for the
| "release date/time" to be displayed on the page's footer
|
| Using:
| System.Reflection.Assembly
| asm=System.Reflection.Assembly.GetExecutingAssembly();
| appVer = asm.GetName().Version.ToString();
|
| // get the location of our executing assembly
| System.IO.FileInfo inf = new System.IO.FileInfo(asm.Location);
| DateTime dt = inf.LastWriteTime;
| appDate = dt.ToString("d MMM yyyy")
|
| log.Info ("asm.Location=" + asm.Location);
|
|
| However, the debug log indicate that it is reading the last write time
from
| c:\winnt\microsoft.net\framework\v1.1.4322\temporary asp.net
|
files\MyProd\0bb3e1a5\e740ffe2\assembly\dl2\a5a61754\024e623d_c70bc601\MyCom
pany.MyDept.MyProd.dll and not c\inetpub\wwwroot\MyProd\bin\MyProd.dll
|
| How can I update my code to read the last modification date/time of where
| the DLL was deployed?
|
| Note the
| 1) Problem happens both on IIS5.1 / Win XP Pro SP2 and IIS6 / Windows
2003
| server
| 2) .Net framework 1.1
| 3) Impersonation is used, impersonating the logged on user (no admin
| priviledges)
|
|
 
Back
Top