System.Reflection.Assembly.GetExecutingAssembly()

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Patrick

    #1

    System.Reflection.Assembly.GetExecutingAssembly()

    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.Reflecti on.Assembly
    asm=System.Refl ection.Assembly .GetExecutingAs sembly();
    appVer = asm.GetName().V ersion.ToString ();

    // get the location of our executing assembly
    System.IO.FileI nfo inf = new System.IO.FileI nfo(asm.Locatio n);
    DateTime dt = inf.LastWriteTi me;
    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\micros oft.net\framewo rk\v1.1.4322\te mporary asp.net
    files\MyProd\0b b3e1a5\e740ffe2 \assembly\dl2\a 5a61754\024e623 d_c70bc601\MyCo mpany.MyDept.My Prod.dll and not c\inetpub\wwwro ot\MyProd\bin\M yProd.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)

  • Steven Cheng[MSFT]

    #2
    RE: System.Reflecti on.Assembly.Get ExecutingAssemb ly()

    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.Locati on 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.CodeBa se instead of the Assembly.Locati on , 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.Reflecti on.Assembly.Get ExecutingAssemb ly()
    | thread-index: AcYLyHaN2xw0eox TSY2durKc+OoAjw ==
    | X-WBNR-Posting-Host: 198.240.128.75
    | From: "=?Utf-8?B?UGF0cmljaw= =?=" <questions@news group.nospam>
    | Subject: System.Reflecti on.Assembly.Get ExecutingAssemb ly()
    | Date: Wed, 28 Dec 2005 08:05:03 -0800
    | Lines: 30
    | Message-ID: <25D09498-702C-435F-91DB-48CF179F36B9@mi crosoft.com>
    | 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.publi c.dotnet.genera l
    | NNTP-Posting-Host: TK2MSFTNGXA03.p hx.gbl 10.40.2.250
    | Path: TK2MSFTNGXA02.p hx.gbl!TK2MSFTN GP08.phx.gbl!TK 2MSFTNGXA03.phx .gbl
    | Xref: TK2MSFTNGXA02.p hx.gbl microsoft.publi c.dotnet.genera l:185171
    | X-Tomcat-NG: microsoft.publi c.dotnet.genera l
    |
    | 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.Reflecti on.Assembly
    | asm=System.Refl ection.Assembly .GetExecutingAs sembly();
    | appVer = asm.GetName().V ersion.ToString ();
    |
    | // get the location of our executing assembly
    | System.IO.FileI nfo inf = new System.IO.FileI nfo(asm.Locatio n);
    | DateTime dt = inf.LastWriteTi me;
    | 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\micros oft.net\framewo rk\v1.1.4322\te mporary asp.net
    |
    files\MyProd\0b b3e1a5\e740ffe2 \assembly\dl2\a 5a61754\024e623 d_c70bc601\MyCo m
    pany.MyDept.MyP rod.dll and not c\inetpub\wwwro ot\MyProd\bin\M yProd.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)
    |
    |

    Comment

    Working...