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(a ssemblynam e,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
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(a
I could solve this by adding an entry to web.config with the current assemblyname, but i don't want it that way
ASKER
that gives me the value of 'nothing'
mmm... try this
' Get our assembly.
Dim executing_assembly As System.Reflection.Assembly = _
Me.GetType.Assembly.GetEnt ryAssembly ()
' Get our namespace.
Dim executing_namespace As String = _
executing_assembly.GetName ().Name.To String()
this is taken from one of our apps and it definetely works here
' Get our assembly.
Dim executing_assembly As System.Reflection.Assembly
Me.GetType.Assembly.GetEnt
' Get our namespace.
Dim executing_namespace As String = _
executing_assembly.GetName
this is taken from one of our apps and it definetely works here
ASKER
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
i still get nothing reference for executing_assembly
i have to point out that this is a web application, not a windows forms application
What kind of magic are you looking to perform with loading a dynamic assembly?
Bob
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 ;)
If you are dealing with web then I think I'll bail out ;)
ASKER
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.dl l"), does it work?
Bob
Bob
ASKER
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.
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
Bob
ASKER
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("RoleProvi der",new MyRoleProvider())
myroleprovider implements a specific interface MyInterface.
then in the DLL:
dim o as MyInterface
o = ctype(httpcontext.current. applicatio n("RolePro vider"),My Interface)
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.GetEnt ryAssembly ()
a.createinstance("MyRolePr ovider",p1 ,p2,p3)
I have solved my problem by doing the following:
in global.asax application_onstart for all apps that use the DLL:
application.add("RoleProvi
myroleprovider implements a specific interface MyInterface.
then in the DLL:
dim o as MyInterface
o = ctype(httpcontext.current.
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.GetEnt
a.createinstance("MyRolePr
Are you developing using something like Web Matrix, or the IDE?
Bob
Bob
ASKER
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
Bob
ASKER
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
Bob
ASKER
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
to get the assembly name...
dim asm as system.reflection.assembly
messagebox.show("My assembly name is " & asm.fullname)