473,722 Members | 2,430 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Can't create delegate for DataAdapater.Ro wUpdated event (reflection)

I am trying to use reflection to add an event handler for the RowUpdated
event of the OracleDataAdapt er object (ODP.NET), but the same thing can be
said for SqlDataAdapter if you only use reflection. The code I supplied is
based on the SqlDataAdapter with reflection.

The error occurs when trying to create the delegate that will be passed in
to EventInfo.AddEv entHandler. I get the following error:
An unhandled exception of type 'System.Argumen tException' occurred in
mscorlib.dll
Additional information: Error binding to target method.
The binding problem is with the second parameter to the event handler. It
is of type SqlRowUpdatedEv entArgs. Again, in reality, I am trying to use
ODP.NET via reflection. So, in this example, I am not referencing the
System.Data or System.Data.Cli ent namespace directly.

Without referencing the namespace, how would one declare a delegate's method
that has a parameter type that exists in a namespace not being referenced
(does that make sense?)?

I have included some sample code to illustrate the problem. The first
CreateDelegate will succeed with the using System.Data* lines *not*
commented out because you can use the SqlRowUpdatedEv entArgs parameter. If
you comment out the "using System.Data" and "using System.Data.Sql Client"
lines, how do you create the delegate?

Again, I am illustrating my problem here using Sql types, because not
everyone has ODP.NET installed.

Tim

using System;

using System.Reflecti on;

// TAKE THE FOLLOWING TWO LINES OUT TO DEPEND SOLELY ON REFLECTION

using System.Data;

using System.Data.Sql Client;

namespace ReflectionEvent Test

{

class Class1

{

[STAThread]

static void Main(string[] args)

{

CreateSqlDelega te();

}

static public void CreateSqlDelega te()

{

Module systemData = GetSystemDataMo dule();

Type t = systemData.GetT ype( "System.Data.Sq lClient.SqlData Adapter" );

object sqlDAObj = Activator.Creat eInstance( t );

EventInfo ei = t.GetEvent( "RowUpdated " );

// This one works because the second parameter in the handler is of type
SqlRowUpdatedEv entArgs

Delegate d1 = Delegate.Create Delegate( ei.EventHandler Type, typeof(
Class1 ), "rowUpdated_Par amIsProperSql" );

// These other three produce the following error:

//

// An unhandled exception of type 'System.Argumen tException' occurred in
mscorlib.dll

//

// Additional information: Error binding to target method.

// Causes error

Delegate d2 = Delegate.Create Delegate( ei.EventHandler Type, typeof(
Class1 ), "rowUpdated_Par amIsObject" );

// Causes error

Delegate d3 = Delegate.Create Delegate( ei.EventHandler Type, typeof(
Class1 ), "rowUpdated_Par amIsBaseClass" );

// Causes error

Delegate d4 = Delegate.Create Delegate( ei.EventHandler Type, typeof(
Class1 ), "rowUpdated_Par amIsIntPtr" );

}

// THIS WON'T COMPILE WHEN YOU TAKE THE using System.Data* LINES OUT AT THE
TOP

static private void rowUpdated_Para mIsProperSql(ob ject sender,
SqlRowUpdatedEv entArgs e)

{

}

static private void rowUpdated_Para mIsObject(objec t sender, object
oraRowUpdEventA rgs)

{

}

// SqlRowUpdatedEv entArgs is derived from
System.Data.Com mon.RowUpdatedE ventArgs

static private void rowUpdated_Para mIsBaseClass(ob ject sender,
System.Data.Com mon.RowUpdatedE ventArgs e)

{

}

static private void rowUpdated_Para mIsIntPtr(objec t sender, System.IntPtr e)

{

}

static public Module GetSystemDataMo dule()

{

Assembly assembly = null;

Module module = null;

string strongName = "System.Dat a, PublicKeyToken= b77a5c561934e08 9,
Culture=neutral , Version=1.0.500 0.0";

// Load the assembly

assembly = Assembly.Load( strongName );

// Get the module

module = assembly.GetMod ule( "System.Data.dl l" );

return module;

}

}

}
Jul 21 '05 #1
4 2203
Hi Tim,

First of all, I would like to confirm my understanding of your issue. From
your description, I understand that you cannot create a delegate throw
reflection. If there is any misunderstandin g, please feel free to let me
know.

Based on my research, SqlRowUpdatedEv entArgs contains enumeration values
StatementType. As this is not supported by current .NET Framework with
CreateDelegate, we cannot use it.

HTH.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Jul 21 '05 #2
Kevin,

Thanks for the reply, and if you say it can't be done because of a member of
SqlRowUpdatedEv entArgs, I'll accept that. But, in general, I am still
curious as to the resolution of my problem in generic terms. Let me present
my problem another way without Sql or ODP.NET data types.

Suppose I have object O with and event E that are defined in a module M that
I am referencing in my code via reflection. M also defines object A which
is an argument to E. At compile-time, how can I have written code that will
create a delegate that uses A which the compiler knows nothing about?

Is there a way to bind the event delegate to a method with generic arguments
(object?) which, once called by the event, the method uses reflection to
work with the generic arguments (object?) to access their
properties/methods?

I noticed when using the reference that defines SqlRowUpdatedEv entHandler
that it has an overloaded constructor. When adding a RowUpdated event with
System.Data.Cli ent properly referenced, the code looks something like this:

SqlDataAdapter sda = new SqlDataAdapter( .....);

sda.RowUpdated += new SqlRowUpdatedEv entHandler(sda_ RowUpdated );

private static void sda_RowUpdated( object sender, SqlRowUpdatedEv entArgs e)

{

}
But if you put your cursor anywhere in between the parentheses of the
SqlRowUpdatedEv entHandler constructor and hit Ctrl-Shift-Space to bring up
IntelliSense, you can walk through its two constructors. The first
constructor takes a single argument like the code above illustrates, but the
second constructor takes two arguments, "object object, System.IntPtr
method".

Could the second constructor somehow be used when using reflection to define
the delegate?

Tim
Jul 21 '05 #3
Hi Tim,

As far as I know, currently, we don't have a workaround. Since you can use
another overload of constructor to create the delegate the reference to the
argument is still a SqlRowUpdatedEv entArgs object which contains a
enumeration member which is not supported. Based on my research, the only
way to overcome this is make the enumeration value to be an integer. Sorry
for the inconvenience.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Jul 21 '05 #4
Kevin,

Thank you for the information.

Tim
Jul 21 '05 #5

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

Similar topics

5
624
by: Torben | last post by:
For test purposes I attach an event to a control, say a TextBox TextChanged event. At another time the same event delegate is attached to some other control, maybe a listbox. Same event function every where. The event function should happen only once for that control (and then, maybe again if it is attached to the control again). Could I make that deattachment operation general? could the function find out what event it is attaced?...
6
1508
by: Bill Davidson | last post by:
All: I'd like to create a delegate for a property (as opposed to a method). Can I do this? If so, please teach me the syntactic magic. For example, suppose I have a boolean ready-only property defined in an instance of a class name SomeObj as follows: public bool TheValue {
4
1005
by: johngilmer | last post by:
I posted this question a couple days ago on , but didn't get any answers, so I will try here. My issue: there is a link button with an event handler for a Click event. I want to create another link button that will act exactly like the first. So I want to set its Click event handler to be the same as the first one. But I can't figure out how I can see what the first one's event handler is. thanks in advance.
4
374
by: Tim Werth | last post by:
I am trying to use reflection to add an event handler for the RowUpdated event of the OracleDataAdapter object (ODP.NET), but the same thing can be said for SqlDataAdapter if you only use reflection. The code I supplied is based on the SqlDataAdapter with reflection. The error occurs when trying to create the delegate that will be passed in to EventInfo.AddEventHandler. I get the following error: An unhandled exception of type...
7
1777
by: Ant | last post by:
Hello, Very simple question but one I need clarified. Which part of the statement below is considered the 'delegate'? Is it the 'new System.EventHandler' or the btnAccept_Click? or is it the piece of code which doesn't appear here, but abstracts the btnAccept_Click method?
6
2443
by: keith.thornhill | last post by:
hi all, lets say i have a usercontrol which implements a custom interface. like so: ------------------------------------------------- interface IMyInterface sub buttonClick() end interface
0
2569
by: slemen | last post by:
My GridView is bound in VB code to a DataTable. The RowUpdating event fires when the row's Update linkbutton is clicked and the row contains the old, pre-edited values (as is expected.) However, the RowUpdated event never fires. The debugger shows the Page_PreRender event fires immediately after the RowUpdating event fires. I tried calling the GridView's UpdateRow method from the RowCommand event and looking at the values afterward...
1
8293
by: kret | last post by:
Hi, this is my first post so first of all I would like to say hello :) Now getting to my problem. In my job I have to create an ActiveX control in .NET 1.1 that can be lunched from IE. This part is done but next requirement is that after closing ActiveX I have to redirect parent page to location X or Y depending on how the
7
1750
by: tadmill | last post by:
Is it possible for a class that accepts a generic type, to re-create another instance of itself with a property type of the passed class? ex. public class SomeClass<T> { private PropertyInfo propInfos; private Type objectType = typeof(T); public SomeClass()
0
8863
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
8739
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
9238
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
9088
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...
0
8052
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5995
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
4502
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
4762
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3207
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

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.