Search:
Namespaces
Discussions
.NET v1.1
Feedback
System.Reflection - Loading Assemblies
Messages
Related Types
This message was discovered on
ASPFriends.com 'ngfx-reflection' list
.
Jon Ceanfaglione
I'm having some difficulty with the Reflection class and I'm at my wits end.
If I do this everything works fine:
public void invokeMethod(string sMethodName)
{
object obj = null;
Type type = typeof(MyNameSpace.MyClass);
// Create an instance of AccountEnumeration in Memory
obj =
Activator
.CreateInstance (type);
//Get info for method
MethodInfo mi = type.GetMethod(sMethodName);
//invoke method
mi.Invoke(obj, null);
}
But let's say I want to make the class that is loaded dynamic too (code
below). I get an error that the assembly could not be found. Any ideas?
Thanks!
public void invokeMethod(string sMethodName, string sClassName)
{
object obj = null;
Assembly a = null;
Type type = null;
try
{
//Get routing class type
type = a.GetType(sClassName);
}
catch(Exception e)
{
System.Web.
HttpContext
.Current.Response.Write(e.Message);
}
// Create an instance of AccountEnumeration in Memory
obj =
Activator
.CreateInstance (type);
//Get info for method
MethodInfo mi = type.GetMethod(sMethodName);
//invoke method
mi.Invoke(obj, null);
}
__________________________________________________
The information contained in this communication is intended only for the use
of the recipient named above, and may be legally privileged, confidential
and exempt from disclosure under applicable law. If the reader of this
communication is not the intended recipient, you are hereby notified that
any dissemination, distribution, or copying of this communication, or any of
its contents, is strictly prohibited. If you have received this
communication in error, please re-send this communication to the sender and
delete the original communication and any copy of it from your computer
system. Thank you.
Reply to this message...
Sinnott, John
Don't you need to set the assemly reference "a" to a valid object?
- John
[Original message clipped]
Reply to this message...
Jon Ceanfaglione
It's there.... bad cut and paste -- the function looks like:
public void invokeMethod(string sMethodName, string sClassName, string
sNameSpace)
{
object obj = null;
Assembly a = null;
Type type = null;
try
{
a =
Assembly
.Load(sNameSpace);
}
catch(Exception e)
{
System.Web.
HttpContext
.Current.Response.Write(e.Message);
}
//Get routing class type
type = a.GetType(sClassName);
// Create an instance of AccountEnumeration in Memory
obj =
Activator
.CreateInstance (type);
//Get info for method
MethodInfo mi = type.GetMethod(sMethodName);
//invoke method
mi.Invoke(obj, null);
}
the line I get the error is:
a =
Assembly
.Load();
-----Original Message-----
From: Sinnott, John [mailto:
Click here to reveal e-mail address
]
Sent: Wednesday, November 21, 2001 2:34 PM
To: ngfx-reflection
Subject: [ngfx-reflection] RE: System.Reflection - Loading Assemblies
Don't you need to set the assemly reference "a" to a valid object?
- John
[Original message clipped]
| [ngfx-reflection] member
Click here to reveal e-mail address
= YOUR ID
|
http://www.asplists.com/asplists/aspngbeta.asp
= JOIN/QUIT
|
http://www.asplists.com/search
= SEARCH Archives
__________________________________________________
The information contained in this communication is intended only for the use
of the recipient named above, and may be legally privileged, confidential
and exempt from disclosure under applicable law. If the reader of this
communication is not the intended recipient, you are hereby notified that
any dissemination, distribution, or copying of this communication, or any of
its contents, is strictly prohibited. If you have received this
communication in error, please re-send this communication to the sender and
delete the original communication and any copy of it from your computer
system. Thank you.
Reply to this message...
<1154-114@onlinehome.de>
It's not clear, what your sNameSpace is - i would try
string filePath ; //some file path like
//System.
Environment
.CurrentDirectory +
"\\MyDll.dll"
Assembly
.LoadFrom(filePath);
-----Original Message-----
From: Jon Ceanfaglione [mailto:
Click here to reveal e-mail address
]
Sent: Mittwoch, 21. November 2001 21:18
To: ngfx-reflection
Subject: [ngfx-reflection] RE: System.Reflection - Loading Assemblies
It's there.... bad cut and paste -- the function looks like:
public void invokeMethod(string sMethodName, string sClassName, string
sNameSpace)
{
object obj = null;
Assembly a = null;
Type type = null;
try
{
a =
Assembly
.Load(sNameSpace);
}
catch(Exception e)
{
System.Web.
HttpContext
.Current.Response.Write(e.Message);
}
//Get routing class type
type = a.GetType(sClassName);
// Create an instance of AccountEnumeration in Memory
obj =
Activator
.CreateInstance (type);
//Get info for method
MethodInfo mi = type.GetMethod(sMethodName);
//invoke method
mi.Invoke(obj, null);
}
the line I get the error is:
a =
Assembly
.Load();
-----Original Message-----
From: Sinnott, John [mailto:
Click here to reveal e-mail address
]
Sent: Wednesday, November 21, 2001 2:34 PM
To: ngfx-reflection
Subject: [ngfx-reflection] RE: System.Reflection - Loading Assemblies
Don't you need to set the assemly reference "a" to a valid object?
- John
[Original message clipped]
| [ngfx-reflection] member
Click here to reveal e-mail address
= YOUR ID
|
http://www.asplists.com/asplists/aspngbeta.asp
= JOIN/QUIT
|
http://www.asplists.com/search
= SEARCH Archives
__________________________________________________
The information contained in this communication is intended only for the
use of the recipient named above, and may be legally privileged,
confidential and exempt from disclosure under applicable law. If the
reader of this communication is not the intended recipient, you are
hereby notified that any dissemination, distribution, or copying of this
communication, or any of its contents, is strictly prohibited. If you
have received this communication in error, please re-send this
communication to the sender and delete the original communication and
any copy of it from your computer system. Thank you.
| [ngfx-reflection] member
Click here to reveal e-mail address
= YOUR ID
|
http://www.asplists.com/asplists/aspngbeta.asp
= JOIN/QUIT
|
http://www.asplists.com/search
= SEARCH Archives
Reply to this message...
Jon Ceanfaglione
I'll try using LoadFrom. But, sNameSpace should and is the name of the
namespace for the class:
namespace SomeNameSpace{
public class SomeClass
{
public void SomeMethod()
{
}
}
}
Thus, I could invoke SomeMethod by using:
invokeMethod(SomeMethod,SomeClass,SomeNameSpace)
I don't know if that clears it up, but I will try the LoadFrom method.
Thanks.
Jon
-----Original Message-----
From:
Click here to reveal e-mail address
[mailto:
Click here to reveal e-mail address
]
Sent: Wednesday, November 21, 2001 5:42 PM
To: ngfx-reflection
Subject: [ngfx-reflection] RE: System.Reflection - Loading Assemblies
It's not clear, what your sNameSpace is - i would try
string filePath ; //some file path like
//System.
Environment
.CurrentDirectory +
"\\MyDll.dll"
Assembly
.LoadFrom(filePath);
-----Original Message-----
From: Jon Ceanfaglione [mailto:
Click here to reveal e-mail address
]
Sent: Mittwoch, 21. November 2001 21:18
To: ngfx-reflection
Subject: [ngfx-reflection] RE: System.Reflection - Loading Assemblies
It's there.... bad cut and paste -- the function looks like:
public void invokeMethod(string sMethodName, string sClassName, string
sNameSpace)
{
object obj = null;
Assembly a = null;
Type type = null;
try
{
a =
Assembly
.Load(sNameSpace);
}
catch(Exception e)
{
System.Web.
HttpContext
.Current.Response.Write(e.Message);
}
//Get routing class type
type = a.GetType(sClassName);
// Create an instance of AccountEnumeration in Memory
obj =
Activator
.CreateInstance (type);
//Get info for method
MethodInfo mi = type.GetMethod(sMethodName);
//invoke method
mi.Invoke(obj, null);
}
the line I get the error is:
a =
Assembly
.Load();
-----Original Message-----
From: Sinnott, John [mailto:
Click here to reveal e-mail address
]
Sent: Wednesday, November 21, 2001 2:34 PM
To: ngfx-reflection
Subject: [ngfx-reflection] RE: System.Reflection - Loading Assemblies
Don't you need to set the assemly reference "a" to a valid object?
- John
[Original message clipped]
| [ngfx-reflection] member
Click here to reveal e-mail address
= YOUR ID
|
http://www.asplists.com/asplists/aspngbeta.asp
= JOIN/QUIT
|
http://www.asplists.com/search
= SEARCH Archives
__________________________________________________
The information contained in this communication is intended only for the
use of the recipient named above, and may be legally privileged,
confidential and exempt from disclosure under applicable law. If the
reader of this communication is not the intended recipient, you are
hereby notified that any dissemination, distribution, or copying of this
communication, or any of its contents, is strictly prohibited. If you
have received this communication in error, please re-send this
communication to the sender and delete the original communication and
any copy of it from your computer system. Thank you.
| [ngfx-reflection] member
Click here to reveal e-mail address
= YOUR ID
|
http://www.asplists.com/asplists/aspngbeta.asp
= JOIN/QUIT
|
http://www.asplists.com/search
= SEARCH Archives
| [ngfx-reflection] member
Click here to reveal e-mail address
= YOUR ID
|
http://www.asplists.com/asplists/aspngbeta.asp
= JOIN/QUIT
|
http://www.asplists.com/search
= SEARCH Archives
__________________________________________________
The information contained in this communication is intended only for the use
of the recipient named above, and may be legally privileged, confidential
and exempt from disclosure under applicable law. If the reader of this
communication is not the intended recipient, you are hereby notified that
any dissemination, distribution, or copying of this communication, or any of
its contents, is strictly prohibited. If you have received this
communication in error, please re-send this communication to the sender and
delete the original communication and any copy of it from your computer
system. Thank you.
Reply to this message...
System.Activator
System.Environment
System.Reflection.Assembly
System.Reflection.MethodInfo
System.Web.HttpContext
Ad
MBR BootFX
Best-of-breed application framework for .NET projects, developed by Matthew Baxter-Reynolds and MBR IT
Copyright © Matthew Baxter-Reynolds 2001-2008. '.NET 247 Software Development Services' is a trading style of MBR IT Solutions Ltd.
Contact Us
-
Terms of Use
-
Privacy Policy
-
www.dotnet247.com