473,657 Members | 2,432 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Reflecti on.Assembly SampleAssembly;
SampleAssembly =
System.Reflecti on.Assembly.Loa dFrom("C:\\Simp leSolutions\\as mload\\asmtoloa d
\\bin\\Debug\\a smtoload.dll");
System.Type[] Types = SampleAssembly. GetTypes();
foreach (System.Type oType in Types)
{
System.Console. WriteLine(oType .Name.ToString( ));
string strName = oType.Name.ToSt ring();
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.Threadin g.Thread.Sleep( 5000);
}

}
}

Nov 16 '05 #1
3 1529
Almost there,

try;
System.Object pObj = System.Activato r.CreateInstanc e(oType);
System.Reflecti on.MethodInfo[] vMethods =
oType.GetMethod s(BindingFlags. Public | BindingFlags.In stance);
for(int vIdx=0; vIdx< vMethods.Length ; vIdx++)
{
string vName = vMethods[vIdx].Name;
System.Console. WriteLine("Invo ke method " + vName + " with 2 string
arguements");
object[] vArgs = new object[2];
vArgs[0] = "My string arguement #1";
vArgs[1] = "My string arguement #2";
oType.InvokeMem ber(vName, BindingFlags.In vokeMethod, null, pObj, vArgs);
}

You will get some errors if you run this "as is", due to the fact that all
the methods will not take 2 string arguements - but this should get you
heading in the right direction (for all you cross posts!)

- Colin

"Daniel" <so************ *******@yahoo.c om> wrote in message
news:%2******** ********@TK2MSF TNGP10.phx.gbl. ..
how do i access methods when the .net assembly was loaded with late biding?
class Class1
{
public static void Main()
{
System.Reflecti on.Assembly SampleAssembly;
SampleAssembly =
System.Reflecti on.Assembly.Loa dFrom("C:\\Simp leSolutions\\as mload\\asmtoloa d \\bin\\Debug\\a smtoload.dll");
System.Type[] Types = SampleAssembly. GetTypes();
foreach (System.Type oType in Types)
{
System.Console. WriteLine(oType .Name.ToString( ));
string strName = oType.Name.ToSt ring();
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.Threadin g.Thread.Sleep( 5000);
}

}
}

Nov 16 '05 #2
Hello Daniel,

Your best bet for late binding is to use VB .NET. It's way too much work
to program late binding code in C# using Reflection...
how do i access methods when the .net assembly was loaded with late
biding?

class Class1
{
public static void Main()
{
System.Reflecti on.Assembly SampleAssembly;
SampleAssembly =
System.Reflecti on.Assembly.Loa dFrom("C:\\Simp leSolutions\\as mload\\asm
toload
\\bin\\Debug\\a smtoload.dll");
System.Type[] Types = SampleAssembly. GetTypes();
foreach (System.Type oType in Types)
{
System.Console. WriteLine(oType .Name.ToString( ));
string strName = oType.Name.ToSt ring();
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.Threadin g.Thread.Sleep( 5000);
}
}
}

Nov 16 '05 #3
try out this code:
It loads a form from a dll calling the show method.
I post it in another thread as well.

string assembly = "ClassLibrary1. dll";
string method = "Show";
string type = "Form1";
Assembly assemblyInstanc e = Assembly.LoadFr om(assembly);
assemblyInstanc e.GetType(type) .InvokeMember(m ethod, BindingFlags.Pu blic |
BindingFlags.In vokeMethod |
BindingFlags.In stance,null,ass emblyInstance.C reateInstance(t ype), null);

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

class Class1
{
public static void Main()
{
System.Reflecti on.Assembly SampleAssembly;
SampleAssembly =
System.Reflecti on.Assembly.Loa dFrom("C:\\Simp leSolutions\\as mload\\asmtoloa d
\\bin\\Debug\\a smtoload.dll");
System.Type[] Types = SampleAssembly. GetTypes();
foreach (System.Type oType in Types)
{
System.Console. WriteLine(oType .Name.ToString( ));
string strName = oType.Name.ToSt ring();
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.Threadin g.Thread.Sleep( 5000);
}

}
}

Nov 16 '05 #4

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

Similar topics

3
1654
by: 8leggeddj | last post by:
Hello, I am having a problem when using access xp as a frontend for sql server 2000. I have been trying to update a number of stored procedures (Just simple adding fields etc) which results in access crashing with event ID 1000 and 1001. Does anyone have any ideas as to what could be the problem? Thanks in advance..
1
384
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 = System.Reflection.Assembly.LoadFrom("C:\\SimpleSolutions\\asmload\\asmtoload \\bin\\Debug\\asmtoload.dll");
1
2452
by: Marcus Leon | last post by:
Access freezes when we attempt to link to and then open an Oracle table that has a Timestamp column. Does anyone know why? This issue does not occur if you attempt to link to and open a table that has Date fields. Thanks, Marcus.
2
2571
by: Chris Hankey | last post by:
I having a strange and annoying problem where Access crashes when the user copies (to the clipboard) the results of a query. The message is not very helpful. It simply says - "Microsoft Access has encountered a problem and needs to close. We are sorry for the inconvienience". The MDB is the front-end portion of an Access application. Most of the tables are linked to the back end. Including the tables used to generate the query in...
4
6890
by: Matt Sawyer | last post by:
I am attempting to use an API (CxApiOem.dll) that has a large number of defines and complicated structs. It's just too much hassle to attempt to use DLLImport to make the desired API calls. Instead, I created a managed C++ DLL (OneBoxAPI.dll) that wraps the desired API calls in a manner which is easy to call from C#. This way I can use the header files that are part of the API for all the defines and structs. I am having a problem...
5
1345
by: ahaupt | last post by:
Hi all, Do you know if it is possible to hide class methods when the class has not been "properly" instantiated? Say in the following example, I'd like to hide or disable Drive() when the numWheels == 0. class Car {
0
1252
by: John H | last post by:
Hi, Strange error with serialisaation on .net 1.1 Sp1 when a the assembly containing the type is in the Gac as well as on e.g c:\customdlls. ObjValue in below code is populated with and array of classes which are defined in an assembly loaded from c:\customdlls using loadfrom. This same assembly is also in the gac. The below code snippet fails on last line with error "An unhandled exception of type 'System.InvalidOperationException'
4
2649
by: =?Utf-8?B?RUdPTg==?= | last post by:
nHi! We have a C# .NET application (exe) that is started by a service (like a watchdog) and the application is thereby runing as Local System account. On cetain computers (only a very few of thousands) it seems like the call InternetGetConnectedState gets FALSE back (even when there is a connection) and when i check GetLastError it says 5=Access denied, that InternetGetConnectedState got Access denied and thereby returns false (I...
1
1391
by: ken estes | last post by:
Have an older access program that I loaded to a mass storage device to upload into my laptop (Vista). When I try to initiate the Access program a display comes up saying I need to reformat the older program. Any advice on how to do so?
0
8395
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8310
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8732
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8503
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8605
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6166
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5632
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4155
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4306
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.