473,472 Members | 1,717 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

C# EventArgs.Properties are Null when handled in VB.NET

I'm raising an event from a C# component and trying to catch it in a VB.NET Windows application. The VB app recognizes my custom EventArgs object and catches the event. However, when I try to read any of the properties they are null or nothing. The EventArgs object itself is alive and well.

Here's some code:

C# Event

// HANDFOUND EVENT CODE
public event HandFoundEventHandler HandFound;

public delegate void HandFoundEventHandler(object sender,
HandFoundEventArgs e);

public class HandFoundEventArgs : EventArgs
{
// Properties.
public string TableTitle;
public string HandContents;
// Constructor.
public HandFoundEventArgs(string TableTitle, string HandContents)
{
TableTitle = TableTitle;
HandContents = HandContents;
}
}

....function in another class
.... code snipped...time to raise event
HandFoundEventArgs e = new HandFoundEventArgs(tableTitle, handContents);
OnHandFound(e);

finally, here's "OnHandFound"
protected virtual void OnHandFound(HandFoundEventArgs e)
{
if (HandFound != null)
{
HandFound(this, e);
}
}
'-------------------------------------------------------------------------------------------
All this seems to work fine. The following VB.NET code handles the event.

' EVENT HANDLER for the HAND FINDER OBJECT
Private Shared Sub myHandFinder_HandFound(ByVal Sender As Object, ByVal e As HandFoundEventArgs) Handles myHandFinder.HandFound

System.Diagnostics.Debug.Assert(Not e.TableTitle Is Nothing, "Nothing.")
System.Diagnostics.Debug.Assert(Not e.HandContents Is Nothing, "Nothing")

Dim tableNumber As String = ParseTableNumber(e.TableTitle)
'-------------------------------------------------------------------------------

Both Assert return false and first line throws a Null Object Exception.

Thanks for you help,
D

Jul 21 '05 #1
1 2138
Change your constructor for the HandFOundEventArgs to:

public HandFoundEventArgs(string TableTitle, string HandContents)
{
this.TableTitle = TableTitle;
this.HandContents = HandContents;
}

HTH

David

"Diotima" <Di*****@discussions.microsoft.com> wrote in message
news:9E**********************************@microsof t.com:
I'm raising an event from a C# component and trying to catch it in a
VB.NET Windows application. The VB app recognizes my custom EventArgs object
and catches the event. However, when I try to read any of the properties
they are null or nothing. The EventArgs object itself is alive and well.

Here's some code:

C# Event

// HANDFOUND EVENT CODE
public event HandFoundEventHandler HandFound;

public delegate void HandFoundEventHandler(object sender,
HandFoundEventArgs e);

public class HandFoundEventArgs : EventArgs
{
// Properties.
public string TableTitle;
public string HandContents;
// Constructor.
public HandFoundEventArgs(string TableTitle, string HandContents)
{
TableTitle = TableTitle;
HandContents = HandContents;
}
}

...function in another class
... code snipped...time to raise event
HandFoundEventArgs e = new HandFoundEventArgs(tableTitle, handContents);
OnHandFound(e);

finally, here's "OnHandFound"
protected virtual void OnHandFound(HandFoundEventArgs e)
{
if (HandFound != null)
{
HandFound(this, e);
}
}

'---------------------------------------------------------------------------
----------------
All this seems to work fine. The following VB.NET code handles the
event.

' EVENT HANDLER for the HAND FINDER OBJECT
Private Shared Sub myHandFinder_HandFound(ByVal Sender As Object, ByVal e
As HandFoundEventArgs) Handles myHandFinder.HandFound

System.Diagnostics.Debug.Assert(Not e.TableTitle Is Nothing, "Nothing.")
System.Diagnostics.Debug.Assert(Not e.HandContents Is Nothing,
"Nothing")

Dim tableNumber As String = ParseTableNumber(e.TableTitle)

'---------------------------------------------------------------------------
----

Both Assert return false and first line throws a Null Object Exception.

Thanks for you help,
D


Jul 21 '05 #2

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

Similar topics

4
by: Steve Amey | last post by:
Hi all I am creating a basic control to perform some tasks, and I want to declare some events to be raised so they can be handled from the form that the control is on. I can create my own Event...
1
by: Jack Addington | last post by:
I have a 3rd party object that fires an itemchanged event when someone edits some data on a form. This event has a custom eventArgs that has a field called ActionCode. In the code of the event,...
1
by: Diotima | last post by:
I'm raising an event from a C# component and trying to catch it in a VB.NET Windows application. The VB app recognizes my custom EventArgs object and catches the event. However, when I try to read...
4
by: cashdeskmac | last post by:
I have created a control and added a few properties. One of these is an array of DateTime objects, looking like this: public DateTime MyDates { get { return theDate;} set {theDate =...
6
by: clintonG | last post by:
When I use e. in an event handler all Intellisense wants to show me is: // Event handler protected void BuildNewFileButton_Click(Object sender, EventArgs e) { // can only 'see" these properties...
6
by: Michael.Suarez | last post by:
Consider the TextBox Control. It has a KeyPress event of type KeyPressEventHandler which passes a KeyPressEventArgs to whatever method is assigned to the event. When you set e.Handled = false...
13
by: Dave | last post by:
When using the properties designer to store application wide properties how do you get this to work across a project group containing an EXE and a collection of DLLs. I'm using C#.Net 2005. I...
2
by: Brian Pelton | last post by:
I am trying to bind a textbox to the property of a property. This code works when nested property is not null, but it fails when nested is null. (It fails when SiteLine.Site is null.) The...
3
by: Tony | last post by:
Hello! One more thing assume I create an event and an object derived from the eventArgs containing some info about the event. Then create another event also with an object derived from the...
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
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...
1
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...
0
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...
1
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...
0
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...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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 ...

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.