Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Discovering the routine and app name at run time

Status
Not open for further replies.

CosmicCharlie

Programmer
Jun 30, 2006
44
US
Does anyone know how to programatically identify the name of the currently running routine and application at run time? Does this require reflection?

I need this to pass the name to an error handler.

Thanks.
 
Heya CC, here is the code from the About box we use, it should pull everything you need from the application.
Code:
      Dim Title As String
      Dim Description As String
      Dim Company As String
      Dim Product As String
      Dim Copyright As String
      Dim Version As String
      Dim Configuration As String
      Dim a As [Assembly] = [Assembly].GetEntryAssembly()
      Dim attr As Object
      For Each attr In a.GetCustomAttributes(False)
        If TypeOf attr Is AssemblyTitleAttribute Then
          Title = CType(attr, AssemblyTitleAttribute).Title
        ElseIf TypeOf attr Is AssemblyDescriptionAttribute Then
          Description = CType(attr, AssemblyDescriptionAttribute).Description
        ElseIf TypeOf attr Is AssemblyCompanyAttribute Then
          Company = CType(attr, AssemblyCompanyAttribute).Company
        ElseIf TypeOf attr Is AssemblyProductAttribute Then
          Product = CType(attr, AssemblyProductAttribute).Product
        ElseIf TypeOf attr Is AssemblyCopyrightAttribute Then
          Copyright = CType(attr, AssemblyCopyrightAttribute).Copyright
        ElseIf TypeOf attr Is AssemblyVersionAttribute Then
          Version = CType(attr, AssemblyVersionAttribute).Version
        ElseIf TypeOf attr Is AssemblyInformationalVersionAttribute Then
          Version = CType(attr, AssemblyInformationalVersionAttribute).InformationalVersion
        ElseIf TypeOf attr Is AssemblyConfigurationAttribute Then
          Configuration = CType(attr, AssemblyConfigurationAttribute).Configuration
        End If
      Next
      If Version = "" Then Version = Application.ProductVersion


      Me.Text = "About: " & Title
      Me.lblAppName.Text = Title
      Me.lblProductVersion.Text = Product & " v" & Version
      Me.lblDesc.Text = Description
      Me.lblCopyright.Text = Copyright & " by " & Company
      Me.lblConfiguration.Text = Configuration

The calling procedure I don't have code handy for, but you could try poking arround in system.Reflection.Assembly.GetCallingAssembly

-Rick

VB.Net Forum forum796 forum855 ASP.NET Forum
[monkey]I believe in killer coding ninja monkeys.[monkey]
 
Come to think of it, I believe that's where I'm grabbing the calling method from also.

The namespace structure we use was entirely under our company's initials. (GFC.Enumerations.*, GFC.Data.*, GFC.General.*, etc...)

I parsed the exception stack trace for the string "GFC" to find what the last block of our code threw the exception was.

-Rick

VB.Net Forum forum796 forum855 ASP.NET Forum
[monkey]I believe in killer coding ninja monkeys.[monkey]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top