Link to home
Start Free TrialLog in
Avatar of Darth_helge
Darth_helge

asked on

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
Avatar of cubixSoftware
cubixSoftware

hi

to get the assembly name...


dim asm as system.reflection.assembly

messagebox.show("My assembly name is " & asm.fullname)
Avatar of Darth_helge

ASKER

that gives me the value of 'nothing'
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


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
Avatar of Bob Learned
What kind of magic are you looking to perform with loading a dynamic assembly?

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

If you are dealing with web then I think I'll bail out ;)
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.
When you put the DLL in the bin folder on the web server, and call Assembly.LoadFrom("..\bin\DLLFile.dll"), does it work?

Bob
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.
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
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)
Are you developing using something like Web Matrix, or the IDE?

Bob
i use vs.net 2005
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
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
May I be so bold as to ask what you are trying to accomplish here?

Bob

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

ASKER CERTIFIED SOLUTION
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial