finding current namespace in runtime

Hello

How can I determine the assembly name of the running application that hosts my DLL (runtime)?

I want to use this to do the following:
Use Activator.CreateInstance(assemblyname,typename) where assemblyname is the name of the running application and typename is a predetermined name of a class of a specific type. i know the typename, it's the assemblyname that is the problem.

I could solve this by adding an entry to web.config with the current assemblyname, but i don't want it that way
LVL 5
Darth_helgeAsked:
Who is Participating?
 
Bob LearnedCommented:
1) You don't care what the assembly name is.
2) The class only needs to implement an interface
3) Look for files in the App_Code folder
4) Test to see if the DLL assembly implements the interface:

Imports System.Reflection
Imports System.IO

Public Class InterfaceTester

  Public Function FindInterface(ByVal filePath As String, ByVal interfaceName As String) As Boolean

    For Each fileName As String In Directory.GetFiles(filePath, "*.dll")
      Dim assy As [Assembly] = [Assembly].LoadFrom(fileName)

      For Each definedType As Type In assy.GetTypes()

        If definedType.Name = interfaceName Then
          Return True
        End If

      Next definedType
    Next fileName

    Return False

  End Function  'FindInterface

End Class

Bob


0
 
cubixSoftwareCommented:
hi

to get the assembly name...


dim asm as system.reflection.assembly

messagebox.show("My assembly name is " & asm.fullname)
0
 
Darth_helgeAuthor Commented:
that gives me the value of 'nothing'
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
cubixSoftwareCommented:
mmm... try this

        ' Get our assembly.
        Dim executing_assembly As System.Reflection.Assembly = _
            Me.GetType.Assembly.GetEntryAssembly()
        ' Get our namespace.
        Dim executing_namespace As String = _
            executing_assembly.GetName().Name.ToString()



this is taken from one of our apps and it definetely works here


0
 
Darth_helgeAuthor Commented:
darn...

i still get nothing reference for executing_assembly

i have to point out that this is a web application, not a windows forms application
0
 
Bob LearnedCommented:
What kind of magic are you looking to perform with loading a dynamic assembly?

Bob
0
 
cubixSoftwareCommented:
crashed and burned.... that code snippet was from a winForm application.

If you are dealing with web then I think I'll bail out ;)
0
 
Darth_helgeAuthor Commented:
I want my DLL to create an instance of an object in the main running web-application, and then a get a reference to this object so i can invoke methods on the object.
0
 
Bob LearnedCommented:
When you put the DLL in the bin folder on the web server, and call Assembly.LoadFrom("..\bin\DLLFile.dll"), does it work?

Bob
0
 
Darth_helgeAuthor Commented:
my DLL can lie in different applications. and i want my DLL to load a class from the application. The DLL is to be used in several applications

the name of the class i want to invoke is predetermined, but the name of the main app may vary.
0
 
Bob LearnedCommented:
Can you add a reference to the DLL in the web application?  Would you want to put the DLL in the Global Assembly Cache (GAC) on the web server?

Bob
0
 
Darth_helgeAuthor Commented:
I have a reference to the DLL in the web app.

I have solved my problem by doing the following:

in global.asax application_onstart for all apps that use the DLL:
application.add("RoleProvider",new MyRoleProvider())
myroleprovider implements a specific interface MyInterface.

then in the DLL:
dim o as MyInterface
o = ctype(httpcontext.current.application("RoleProvider"),MyInterface)


The thing is that i want to do this without registering the class in application_onstart
I hoped that i could do somehting like this:
dim a as Reflection.Assembly = Reflection.Assembly.GetEntryAssembly()
a.createinstance("MyRoleProvider",p1,p2,p3)
0
 
Bob LearnedCommented:
Are you developing using something like Web Matrix, or the IDE?

Bob
0
 
Darth_helgeAuthor Commented:
i use vs.net 2005
0
 
Bob LearnedCommented:
If you have a reference, then what is the reason for defining th provider in the Global.asax file?  Do you want every one accessing the application to use the same reference?

Bob
0
 
Darth_helgeAuthor Commented:
the main app has a reference to the dll, but the dll has no reference to the main app, and i want to load a class from the main app into the dll, without knowing the name of the main app at design time
0
 
Bob LearnedCommented:
May I be so bold as to ask what you are trying to accomplish here?

Bob
0
 
Darth_helgeAuthor Commented:

I'm trying to retrive some information from the application that hosts my dll.

In this particulare case I want the application to tell me wich roles is assosiated with a certian user for the current application. The same user can be valid for several apps thats way the current application have to do this jobb. Roles and access behavior is also spesific pr application.

It's the same concept as the 'provider' model microsoft uses in .net 2.0 but i don't want my developers to registere anything in the webconfig file to make thing work.
I just want them to make a class called 'MyProviderForSomthing' wich must implement then 'IMyProviderForSomething' interface and put that class in the App_Code folder.

Maybe I'm far off... ?????

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.