473,749 Members | 2,492 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Help with Type.InvokeMemb er in C#

Hello,

I'm having a problem trying to call a DLL assembly from a C# code with
some special parameters.

I have a global class used to store some parameters and work with them:

public class GlobalClass
{
public int parameter1;
public string parameter2;

public void Method1()
{
}
}
Then I made a class for my PlugIn, which instanciate the GlobalClass
class in a method:

Public class PlugIn
{

public void Method1(GlobalC lass testClass)
{
...
}
}
Finaly, I have a test class which calls the PlugIn.Method1( ) method
using the InvokeMember method:

Public class Test
{

public void TestFunction()
{
Assembly plugin;
Type typeAssembly;
GlobalClass globalClass = new GlobalClass();

plugin = Assembly.LoadFr om("Test.dll") ;
typeAssembly = plugin.GetType( "PlugIn");
object instancePlugin = Activator.Creat eInstance(typeA ssembly);
object arguments = { globalClass };

typeAssembly.In vokeMember("Met hod1", BindingFlags.In vokeMethod,
null, instancePlugin, arguments);
}
When I execute this code, I got an exception "Method not found".
I also tried to use a ref and a ParameterModifi er, but I have the same
exception.
I also tried to use the GlobalClass as return value of the
PlugIn.Method1( ) method, but then I'm not able to cast back the
System.Object returned by the InvokeMember() method to GlobalClass.

Can someone help me ? I'd be really gratefull !!! :-)
Laurent
Nov 17 '05 #1
3 3774
Laurent <mo********@fre e.fr> wrote:
I'm having a problem trying to call a DLL assembly from a C# code with
some special parameters.


Where are you defining GlobalClass? If it's in more than one assembly,
that could well be the problem.

See http://www.pobox.com/~skeet/csharp/plugin.html for why you could be
having the problem.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 17 '05 #2
Could you post the exact error message you get, and indicate at which
line of code you're getting it?

Nov 17 '05 #3
Wow, thanks !!

I used the second solution that was written in your web page, and
everything is working fine. Even if now I must compile in DOS, I'm happy.

Thank you very much for your help, and thanks to Bruce Wood too ! :-)

"Jon Skeet [C# MVP]" <sk***@pobox.co m> a écrit dans le message de news:
MP************* ***********@msn ews.microsoft.c om...
Laurent <mo********@fre e.fr> wrote:
I'm having a problem trying to call a DLL assembly from a C# code
with
some special parameters.


Where are you defining GlobalClass? If it's in more than one assembly,
that could well be the problem.

See http://www.pobox.com/~skeet/csharp/plugin.html for why you could be
having the problem.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 17 '05 #4

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

Similar topics

0
1130
by: David | last post by:
Hi, I have a program in which I used invokemember to late bind to a component. In my code I use: SetupInfo setup; Object objTem = callLateBinding ("BackOfficeServer.BackOffice", "getSetupByDescription", parameter); setup = (Transaction.SetupInfo)objTem;
0
1159
by: JL_327 | last post by:
No one on any of the other boards seem to know In VB.Net this late binding works fine Dim Version As Integer Dim Revision As Integer Dim Wnum As Integer Dim o As System.Array = System.Array.CreateInstance (GetType(Single), 1)
10
16384
by: Dave Leach | last post by:
I am writing a Windows MDI application in C#. I would like to cast an object to a specific type. I know that the object is of a compatible type. The code below shows what I would like to do, but does not compile, where the cast "(c.ItemType)" produces the error "type or namespace could not be found". I know that each control "c" has a public property "ItemType" which returns a Type foreach ( MyComboBox c in cbControls name =...
1
6134
by: Rein Petersen | last post by:
Hi All, I'm invoking Type.InvokeMember() on a COM class (via COMInterop) through a generalized interface. However, each specialized instance (of the COMInterop generic interface) requires slightly different arguments for which I dynamically create the object arguments and it all works nicely. Problem is, in some instances, I have methods which require certain arguments to be referenced (ref string x,...etc). I'm not sure how I can...
8
1126
by: VB Programmer | last post by:
I am trying to send a simple email through my ASP.NET website. This is how I do it. Try System.Web.Mail.SmtpMail.Send("someone@somewhere.com", "me@somewhere.com", "test", "TESTING 123") Catch ex As Exception Response.Write(ex.ToString) End Try Exit Sub
1
1421
by: JS | last post by:
In my project, I am setting Options Strict on. In one place, I have generic code to set values in my objects using a configuration file, code which is trying to set properties of my classes using Invokemember, using this code - dim bindSETPROP As BindingFlags = BindingFlags.IgnoreCase Or BindingFlags.Instance Or BindingFlags.Public Or BindingFlags.SetProperty Me.GetType.InvokeMember(strPropertyName, bindSETPROP, Nothing, Me, objParams) ...
0
1487
by: Jan | last post by:
I just started using .NET Remoting. I have a test system (client) which connects to our device (server) running XP Embedded. When my server object is called it uses a library where reflection (Type.InvokeMethod) is used to dynamically invoke a "command-object" in a list. The list of objects are created when server is started (in UI-thread). Each entry in the command list stores a Type reference, an object reference and the method name.
1
1092
by: Waldy | last post by:
Hi there, the help for InvokeMember shows an example that will not compile: typeof(C).InvokeMember("F", BindingFlags.SetField, null, C, new Object{"strings new value"}); The error message is: A new expression requires () or after type
2
6533
by: james | last post by:
Hi all, I am trying to convert some old VB6 code to .NET. Take this first section (there is more, but hey-ho...) Dim XLApp As Object Dim XLSheet Dim XLBook Dim HeaderItem As String Dim ColCount As Integer ColCount = 1 Set XLApp = CreateObject("EXCEL.Application")
0
8996
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
8832
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
9566
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9388
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...
0
9254
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
6800
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
6078
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();...
1
3319
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2217
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.