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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

GetCallingAssemblyName problem 1

Status
Not open for further replies.

techsmith

MIS
Joined
Jun 27, 2003
Messages
114
Location
GB
Application instantiates class (RoleAccessMgr) from dll, which in turn instantiates singleton subclass (RoleLookup) at which point I need to see the application name - to avoid requiring it in every instance of RoleAccessMgr.

Here is my function - all I get is the name of the dll.

Code:
		Public Shared Function GetCallingAssemblyName() As String
			Dim str As String = System.Reflection.Assembly.GetCallingAssembly.ToString()
			Return str.Substring(0, InStr(str, ",") - 1)
		End Function

Any ideas?
 
So let me get this strait.

your roleaccesmgr is in a dll and each application makes use of that application. And each one make an instantiation of that class.

Then this class uses a singleton rolelookup but every time they do a getinstance it requeries the database (or something else).

Right?

Now you want to prevent it from requering because?

Christiaan Baes
Belgium

"My new site" - Me
 
Are you avoiding "requering" or "requiring"?

Here is the code I use to get the entry application info for my splash screen. You should be able to switch GetEntryAssembly with GetCallingAssembly to get the information you are looking for.

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 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
        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

-Rick

VB.Net Forum forum796 forum855 ASP.NET Forum
[monkey]I believe in killer coding ninja monkeys.[monkey]
 
Thanks Rick - I'd just got to the same point:

Code:
		Public Shared Function GetEntryAssemblyName() As String
			Dim str As String = System.Reflection.Assembly.GetEntryAssembly.ToString()
			Return str.Substring(0, InStr(str, ",") - 1)
		End Function

Problem solved!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top