473,398 Members | 2,125 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,398 software developers and data experts.

TargetInvocationException by event Subscription

Hi,
I am very new to .NET Remoting and I try to run a simple program to
subscribe to an event raised by Remoting Class. The Remoting Server
initiates an instance of Remoting Class as Singleton / Server
activated mode on startup. The Remoting Client accesses the Remoting
Class through the interface of the Class and subscribes to an event of
the Remoting Class that will be fired upon the private member value
change.

The problem is that I can not get the subscribed event fired. Do I
miss a point about Client Registration / Server Registration such that
2 instances are created, 1 on Server Side, 1 on Client Side and the
event subscription is done on the wrong one? Please help :) Thanks in
advance...
[Remoting Class]
public class NetworkElement : MarshalByRefObject, INetworkElement
{
public event AlarmEventHandler AlarmEvent;

private Boolean _ACFail;
public Boolean ACFail
{
get { return _ACFail; }
set
{
_ACFail = value;
OnAlarmsEvent(new AlarmEventArgs(1));
}
}

protected void OnAlarmsEvent(AlarmEventArgs arg)
{
if (AlarmEvent != null) AlarmEvent(this, arg);
}

public void AddAlarmEvent(AlarmEventHandler handler)
{
AlarmEvent += handler;
}
}
[Interface for Remoting Class]
public delegate void AlarmEventHandler(object sender,
AlarmEventArgs arg);

[Serializable]
public class AlarmEventArgs : EventArgs
{
private Int32 _AlarmType;
public Int32 AlarmType
{
get { return _AlarmType; }
}

public AlarmEventArgs(Int32 Type)
{
_AlarmType = Type;
}
}

public interface INetworkElement
{
void AddAlarmEvent(AlarmEventHandler handler);
}


[The Remoting Client]
public class Client : MarshalByRefObject
{

public void SubscribeToAlarmEvent()
{
RemotingConfiguration.Configure("Client.exe.config ");

WellKnownClientTypeEntry[] entry =
RemotingConfiguration.GetRegisteredWellKnownClient Types();
INetworkElement ine =
(INetworkElement)Activator.GetObject(entry[0].ObjectType,
entry[0].ObjectUrl);
ine.AddAlarmEvent(new
AlarmEventHandler(ClientEventHandler));
AlarmType = -1;

}

public void ClientEventHandler(object sender, AlarmEventArgs
arg)
{
AlarmType = arg.AlarmType;
}

}


config files are :

[Server.exe.config]
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.runtime.remoting>
<application>
<channels>
<channel port="6000" displayName="ServerChannel" ref="tcp">
<serverProviders>
<formatter ref="binary" typeFilterLevel="Full"</
formatter>
</serverProviders>

<clientProviders>
<formatter ref="binary"></formatter>
</clientProviders>
</channel>
</channels>
<service>
<wellknown type="NetworkE.NetworkElement, NetworkElement"
objectUri="NetworkElement.rem" mode="Singleton">
</wellknown>
</service>
</application>
</system.runtime.remoting>
</configuration>


[Client.exe.config]
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.runtime.remoting>
<application>
<channels>
<channel port="0" displayName="ClientChannel" ref="tcp">
<clientProviders>
<formatter ref="binary"></formatter>
</clientProviders>
<serverProviders>
<formatter ref="binary" typeFilterLevel="Full"></
formatter>
</serverProviders>
</channel>
</channels>
<client>
<wellknown type="INetworkE.INetworkElement, INetworkElement"
url="tcp://localhost:6000/NetworkElement.rem">

</wellknown>
</client>
</application>
</system.runtime.remoting>
</configuration>

Apr 13 '07 #1
0 1580

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

Similar topics

4
by: dudi | last post by:
Hi, very puzzling... I have one perfectly working solution, in which I use a a.dll which has a class A. that class loads data from the database and for each row deserialize the cell into class A1....
1
by: Greg Patrick | last post by:
My problem: I load an some assemblies (strong named) from a byte array using Assembly.Load(byte). They load fine. But one one of them is actually accessed, it's referenced assemblies can't be...
5
by: wbekker | last post by:
Hi, I'm searching for a good pattern for the following problem: In a large object tree, all object implement a property called IsDirty. That flag is set when a property is modified. If a child...
3
by: Alex K. | last post by:
Hi all I have a class MyClass that exposes event A. Inside the class, I need to catch the moment when some other class subscribes to the event A. In other words, when some other class executes...
2
by: erbilkonuk | last post by:
Hi, I am very new to .NET Remoting and I try to run a simple program to subscribe to an event raised by Remoting Class. The Remoting Server initiates an instance of Remoting Class as Singleton /...
2
by: Zytan | last post by:
I just got a TargetInvocationException from a WebBrowser control, after calling WebBrowser.Document.Write(text), which (internally) calls System.Windows.Forms.HtmlDocument.Write(String text),...
1
by: halekio | last post by:
Hi all, Please bear with me as I've only started programming in C# 2 weeks ago and this is my first contact with OOP. I ran into a situation where I needed to catch an event in an object that...
1
by: halekio | last post by:
Hi all, Please bear with me as I've only started programming in C# 2 weeks ago and this is my first contact with OOP. I ran into a situation where I needed to catch an event in an object that...
10
by: pedrito | last post by:
I have a library I'm using that has a lapsed listener issue. I figured I'd just sneak in and do the unsubscription myself since I don't expect it to be fixed any time soon. So, I have 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
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...
0
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...
0
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
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,...

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.