.NETGURU
dynamic loading of an assembly
Messages   Related Types
This message was discovered on ASPFriends.com 'ngfx-reflection' list.


Wally McClure
I am looking for a way to dynamically load an assembly given the name of
the assembly. Is it appropriate to use the Assembly.Load() method and
specify the assembly name. I assume that this method will pick up the
private assemblies as well as those in the GAC. Is this correct?

Wally

PS. If this is the incorrect list to send this to, please alert me to
the correct one.
Reply to this message...
 
    
Jon Ceanfaglione
Here is something I use:

public void InvokeMethod(string sMethodName, object[] paramArray)
{
    object obj =3D null;
    object[] Parameters =3D null;
        =09
    try
    {
        //Get class type
        Type type =3D typeof([SomeNamespace]);

        // Create an instance of Routing in Memory
        obj =3D Activator.CreateInstance (type);
                =09
        //Get info for method
        MethodInfo mi =3D type.GetMethod(sMethodName);
        int numParams =3D mi.GetParameters().GetLength(0);
        Parameters =3D new object[numParams];
            =09
        if(numParams>0)
        {
            //only pass number of parameters each function needs
            for(int i=3D0;i<numParams;i++)
            {
                Parameters[i] =3D paramArray[i];
            }=09
                =09
            mi.Invoke(obj, Parameters);

        }
        else
        {
            //invoke method
            mi.Invoke(obj,null);
        }
    }
    catch(Exception e)
    {
        LogError(e.Message);
    }
}
-----Original Message-----
From: Wally McClure [mailto:Click here to reveal e-mail address]=20
Sent: Monday, July 01, 2002 10:38 AM
To: ngfx-reflection
Subject: [ngfx-reflection] dynamic loading of an assembly

I am looking for a way to dynamically load an assembly given the name =
of the
assembly. Is it appropriate to use the Assembly.Load() method and =
specify
the assembly name. I assume that this method will pick up the private
assemblies as well as those in the GAC. Is this correct?
=A0
Wally
=A0
PS. If this is the incorrect list to send this to, please alert me to =
the
correct one.
| [ngfx-reflection] member Click here to reveal e-mail address =3D YOUR ID |
http://www.aspfriends.com/aspfriends/ngfx-reflection.asp =3D JOIN/QUIT=20

__________________________________________________=20

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...
 
    
Tom Cabanski
This is useful if the assembly is already loaded. If not...

------------------------------------
Tom Cabanski, President
Objective Advantage, Inc.
eBusiness from Concept to Completion
http://www.oai.cc

-----Original Message-----
From: Jon Ceanfaglione [mailto:Click here to reveal e-mail address]=20
Sent: Monday, July 01, 2002 11:43 AM
To: ngfx-reflection
Subject: [ngfx-reflection] RE: dynamic loading of an assembly

Here is something I use:

public void InvokeMethod(string sMethodName, object[] paramArray)
{
    object obj =3D null;
    object[] Parameters =3D null;
        =09
    try
    {
        //Get class type
        Type type =3D typeof([SomeNamespace]);

        // Create an instance of Routing in Memory
        obj =3D Activator.CreateInstance (type);
                =09
        //Get info for method
        MethodInfo mi =3D type.GetMethod(sMethodName);
        int numParams =3D mi.GetParameters().GetLength(0);
        Parameters =3D new object[numParams];
            =09
        if(numParams>0)
        {
            //only pass number of parameters each function needs
            for(int i=3D0;i<numParams;i++)
            {
                Parameters[i] =3D paramArray[i];
            }=09
                =09
            mi.Invoke(obj, Parameters);

        }
        else
        {
            //invoke method
            mi.Invoke(obj,null);
        }
    }
    catch(Exception e)
    {
        LogError(e.Message);
    }
}
-----Original Message-----
From: Wally McClure [mailto:Click here to reveal e-mail address]=20
Sent: Monday, July 01, 2002 10:38 AM
To: ngfx-reflection
Subject: [ngfx-reflection] dynamic loading of an assembly

I am looking for a way to dynamically load an assembly given the name of =
the
assembly. Is it appropriate to use the Assembly.Load() method and =
specify
the assembly name. I assume that this method will pick up the private
assemblies as well as those in the GAC. Is this correct?
=A0
Wally
=A0
PS. If this is the incorrect list to send this to, please alert me to =
the
correct one.
| [ngfx-reflection] member Click here to reveal e-mail address =3D YOUR ID |
http://www.aspfriends.com/aspfriends/ngfx-reflection.asp =3D JOIN/QUIT=20

__________________________________________________=20

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 =3D YOUR ID
| http://www.aspfriends.com/aspfriends/ngfx-reflection.asp =3D JOIN/QUIT

Reply to this message...
 
    
Russ McClelland
WW91IGNhbiB1c2UgQXNzZW1ibHkuTG9hZCgpIGFuZCBpdCB3aWxsIHBpY2sgdXAgYXNzZW1ibGll
cyB0aGF0IGFyZSBub3QNCnJlZ2lzdGVyZWQgaW4gdGhlIEdBQy4gIFdoZW4geW91IHVzZSBhIGNs
YXNzIGZyb20gdGhlIGxvYWRlZCBhc3NlbWJseSwNCnlvdSBoYXZlIHRvIGZ1bGx5IHF1YWxpZnkg
dGhlIG5hbWVzcGFjZSBhbmQgY2xhc3MgbmFtZS4NCiANCg0KCS0tLS0tT3JpZ2luYWwgTWVzc2Fn
ZS0tLS0tIA0KCUZyb206IFRvbSBDYWJhbnNraSANCglTZW50OiBNb24gNy8xLzIwMDIgMTE6NDYg
QU0gDQoJVG86IG5nZngtcmVmbGVjdGlvbiANCglDYzogDQoJU3ViamVjdDogW25nZngtcmVmbGVj
dGlvbl0gUkU6IGR5bmFtaWMgbG9hZGluZyBvZiBhbiBhc3NlbWJseQ0KCQ0KCQ0KDQoJVGhpcyBp
cyB1c2VmdWwgaWYgdGhlIGFzc2VtYmx5IGlzIGFscmVhZHkgbG9hZGVkLiAgSWYgbm90Li4uDQoJ
DQoJLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tDQoJVG9tIENhYmFuc2tpLCBQ
cmVzaWRlbnQNCglPYmplY3RpdmUgQWR2YW50YWdlLCBJbmMuDQoJZUJ1c2luZXNzIGZyb20gQ29u
Y2VwdCB0byBDb21wbGV0aW9uDQoJaHR0cDovL3d3dy5vYWkuY2MNCgkNCgktLS0t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YXJhbWV0ZXJzKCkuR2V0TGVuZ3RoKDApOw0KCSAgICAgICAgICAg
ICAgICBQYXJhbWV0ZXJzID0gbmV3IG9iamVjdFtudW1QYXJhbXNdOw0KCSAgICAgICAgICAgICAg
ICAgICAgICAgICAgICAgICANCgkgICAgICAgICAgICAgICAgaWYobnVtUGFyYW1zPjApDQoJICAg
ICAgICAgICAgICAgIHsNCgkgICAgICAgICAgICAgICAgICAgICAgICAvL29ubHkgcGFzcyBudW1i
ZXIgb2YgcGFyYW1ldGVycyBlYWNoDQpmdW5jdGlvbiBuZWVkcw0KCSAgICAgICAgICAgICAgICAg
ICAgICAgIGZvcihpbnQgaT0wO2k8bnVtUGFyYW1zO2krKykNCgkgICAgICAgICAgICAgICAgICAg
ICAgICB7DQoJICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBQYXJhbWV0ZXJzW2ldID0g
cGFyYW1BcnJheVtpXTsNCgkgICAgICAgICAgICAgICAgICAgICAgICB9ICAgICAgDQoJICAgICAg
ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgDQoJICAgICAgICAgICAgICAgICAgICAg
ICAgbWkuSW52b2tlKG9iaiwgUGFyYW1ldGVycyk7DQoJDQoJICAgICAgICAgICAgICAgIH0NCgkg
ICAgICAgICAgICAgICAgZWxzZQ0KCSAgICAgICAgICAgICAgICB7DQoJICAgICAgICAgICAgICAg
ICAgICAgICAgLy9pbnZva2UgbWV0aG9kDQoJICAgICAgICAgICAgICAgICAgICAgICAgbWkuSW52
b2tlKG9iaixudWxsKTsNCgkgICAgICAgICAgICAgICAgfQ0KCSAgICAgICAgfQ0KCSAgICAgICAg
Y2F0Y2goRXhjZXB0aW9uIGUpDQoJICAgICAgICB7DQoJICAgICAgICAgICAgICAgIExvZ0Vycm9y
KGUuTWVzc2FnZSk7DQoJICAgICAgICB9DQoJfQ0KCS0tLS0tT3JpZ2luYWwgTWVzc2FnZS0tLS0t
DQoJRnJvbTogV2FsbHkgTWNDbHVyZSBbIG1ha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RwOi8vd3d3LmFzcGZyaWVuZHMuY29tL2FzcGZyaWVuZHMvbmdmeC1yZWZs
ZWN0aW9uLmFzcCA9DQpKT0lOL1FVSVQNCgkNCg0K
Reply to this message...
 
 
System.Activator
System.Reflection.Assembly
System.Reflection.MethodInfo




ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
Ad


Need Dot Net Interview Questions?
Ask ExamGuru, Inc. for advice and help on Passing .Net Interviews
.Net Projects
Best-of-breed application framework for .NET projects, developed by ExamGuru, Inc. and ExamGuru IT
Free .net Help
Commission ExamGuru, Inc. and his team for your next bespoke software project
FogBUGZ
The only bug tracking system carefully crafted with one goal in mind: helping teams create great software.
Awesome Tools
If you don't know about these, you're missing out... IT Certification Questions
IT Interview Questions
Free Oracle 10g Training
MCSE Boortcamp
Cisco Study Guides
Cheap Study Guides
Exact Questions
Dot Net Interview Questions
Oracle OCP
Cheap Travel
Designer Perfumes - Wholesale Prices
Free Programming Tutorials
 
ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
 Copyright © ExamGuru, Inc. 2001-2006
Contact Us - Terms of Use - Privacy Policy - www.dot-net-guru.com - www.examguru.net - www.oraclesource.net - www.itinterviews.net - www.examguru.net/ITCertification