473,386 Members | 1,766 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

how do i access methods when the .net assembly was loaded with late biding?

how do i access methods when the .net assembly was loaded with late biding?

class Class1
{
public static void Main()
{
System.Reflection.Assembly SampleAssembly;
SampleAssembly =
System.Reflection.Assembly.LoadFrom("C:\\SimpleSol utions\\asmload\\asmtoload
\\bin\\Debug\\asmtoload.dll");
System.Type[] Types = SampleAssembly.GetTypes();
foreach (System.Type oType in Types)
{
System.Console.WriteLine(oType.Name.ToString());
string strName = oType.Name.ToString();
System.Object pObj = SampleAssembly.CreateInstance("asmtoload" + "." +
strName);
//System.Console.WriteLine(pObj.IOCTL("foo")); THIS IS A BUILD ERROR
BECAUSE IOCTL method is not accessible, how to access method if type info of
dynamicaly loaded dll?
System.Threading.Thread.Sleep(5000);
}

}
}

Nov 22 '05 #1
1 1285
There are several approaches to invoke a method using reflection. Take a
look at the following .NET framework classes/methods on MSDN/VS.NET-help:
- System.Activator.CreateInstance()
- System.Type.InvokeMember()
- System.Type.GetMember()/GetMembers()
- System.Reflection.MethodInfo/MethodBase

Here's a code sample (console application) that loads itself dynamically and
invokes ToString() on the types it finds:

using System;
using System.Reflection;

class Class1
{
public static void Main()
{
Assembly SampleAssembly =
Assembly.LoadFrom(@"c:\dev\test\bin\debug\test.exe ");
Type[] Types = SampleAssembly.GetTypes();
foreach (Type oType in Types)
{
object instance = Activator.CreateInstance(oType);
string result = (string) oType.InvokeMember( "ToString",
BindingFlags.Instance | BindingFlags.Public | BindingFlags.InvokeMethod,
null, instance, null );
Console.WriteLine(result);
}
}
}

class class2
{
public class2() {}
public override string ToString()
{
return "hello from class2";
}
}

Nov 22 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Nick Malik | last post by:
reposting to a wider audience "Nick Malik" <nickmalik@hotmail.nospam.com> wrote in message news:WYONc.203854$XM6.119642@attbi_s53... > My turn to ask a question > > I am working on a plug-in...
4
by: Nick Malik | last post by:
My turn to ask a question I am working on a plug-in for Sharepoint that will allow a developer to add workflow rules. One of the rules will inform the adapter that it should load a DLL that the...
3
by: Daniel | last post by:
how do i access methods when the .net assembly was loaded with late biding? class Class1 { public static void Main() { System.Reflection.Assembly SampleAssembly; SampleAssembly =...
0
by: Vamsi T via DotNetMonster.com | last post by:
Hi, I'm using .NET CF 2.0. I have a problem in retrieving the exact methods of a Class in CF. When I do a type.GetMethods() (where type is System.Xml.XPath. XPathException for example), I get...
10
by: David | last post by:
Hi Everyone! I am working on a project for a directed study class and am having problems with webservices. I have .NET Framework version 1.1.4322.573 with IIS and Frontpage Extensions...
6
by: dbuchanan | last post by:
I have a Windows Forms application that accesses SQL Server 2k from a small local network. The application has been used for weeks on other systmes but a new install on a new machine retruns...
1
by: tlwright1414 | last post by:
I'm trying to late bind and invoke a method on a .net 2.0 assembly from a .net 1.1 assembly. I'm getting and error 'The format of the file 'myAssembly.dll' is Invalid. Can't figure it out. Any...
5
by: Lyle Fairfield | last post by:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndotnet/html/callnetfrcom.asp The Joy of Interoperability Sometimes a revolution in programming forces you to abandon all...
9
by: JT | last post by:
Here is the overall structure I will be referring to: End-program ProvideWorkFlow.dll Forms and methods that properly manipulate calls to methods in AccessUtils AccessUtils (a web service)...
1
by: GaryGen | last post by:
Hi, I have a VB.NET EXE which needs to remain in house. We would like to have outside people code modules that can be dynamically loaded and used by our EXE. We can place the requirement on the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.