Click here to Skip to main content
15,924,402 members
Home / Discussions / C#
   

C#

 
GeneralRe: Installer for C# app Pin
Dave Kreskowiak27-Oct-05 14:25
mveDave Kreskowiak27-Oct-05 14:25 
QuestionC# Best approach to a windows form application Pin
spookas27-Oct-05 5:09
spookas27-Oct-05 5:09 
QuestionAssembly not found in release mode Pin
cppdotnet27-Oct-05 4:51
cppdotnet27-Oct-05 4:51 
AnswerRe: Assembly not found in release mode Pin
Matt Newman27-Oct-05 5:01
Matt Newman27-Oct-05 5:01 
AnswerRe: Assembly not found in release mode Pin
enjoycrack27-Oct-05 6:53
enjoycrack27-Oct-05 6:53 
GeneralRe: Assembly not found in release mode Pin
cppdotnet27-Oct-05 7:37
cppdotnet27-Oct-05 7:37 
GeneralRe: Assembly not found in release mode Pin
Dave Kreskowiak27-Oct-05 8:27
mveDave Kreskowiak27-Oct-05 8:27 
QuestionEvents over .Net Remoting Pin
Mikke_x27-Oct-05 4:47
Mikke_x27-Oct-05 4:47 
Hi all,

I have a problem I cannot solve by my own. The message is quite long, but I hope that someone is nice enough to read it and give me a hand.
The basic problem is that I cannot sent events over .Net remoting that has an event argument as a class I have created, but strings as arguments works just fine.

I have three projects: Server, Middle and Client.

Server going to generate events and pass them through .Net remoting to the client. The middle project contains the remoted object. It also contains a delegate that is used to define the events generated in the server. The server is remoting the class in the middle project through a TCP channel.

The connection class in the server is remoting the object:
<br />
private void OpenConnection()<br />
{<br />
	BinaryClientFormatterSinkProvider clientProvider = null;<br />
	BinaryServerFormatterSinkProvider serverProvider = <br />
		new BinaryServerFormatterSinkProvider();<br />
	serverProvider.TypeFilterLevel = System.Runtime.Serialization.Formatters.TypeFilterLevel.Full;<br />
              <br />
	IDictionary props = new Hashtable();<br />
	props["port"] = 7889;<br />
	props["typeFilterLevel"] = System.Runtime.Serialization.Formatters.TypeFilterLevel.Full;<br />
	props["name"] = "StatusControl";<br />
<br />
	TcpChannel chan = new TcpChannel(<br />
		props,clientProvider,serverProvider); <br />
<br />
	ChannelServices.RegisterChannel(chan);<br />
<br />
	RemotingConfiguration.RegisterWellKnownServiceType(<br />
	Type.GetType("ProductionStatusControl.DistributedStatusControl, ProductionStatusControl"),"IDistributedControl", WellKnownObjectMode.Singleton ); <br />
<br />
// Singleton class used to retreive messages from the remoted objects<br />
	m_single = StatusSingletonConnection.GetInstance();<br />
<br />
	System.Threading.ThreadStart ts = new System.Threading.ThreadStart( SendMessages );<br />
	System.Threading.Thread t = new System.Threading.Thread( ts );<br />
	t.IsBackground = true;<br />
	t.Start();<br />
}<br />


The middle project has a delegate:
<br />
public delegate void ProductionStatusDelegate( StatusMessage message );<br />

, a class as event argument:
<br />
	/// <summary><br />
	/// A status message from the floating storage<br />
	/// </summary><br />
	[Serializable]<br />
	public class StatusMessage<br />
	{<br />
<br />
		private FloatingStorageEventType m_type;<br />
		private string m_message;<br />
<br />
		/// <summary><br />
		/// Creates a new Status message instance<br />
		/// </summary><br />
		/// <param name="type"></param><br />
		/// <param name="message"></param><br />
		public StatusMessage( FloatingStorageEventType type, string message )<br />
		{<br />
			this.m_message = message;<br />
			this.m_type = type;<br />
		}<br />
<br />
		/// <summary><br />
		/// Gets the type of the message<br />
		/// </summary><br />
		public FloatingStorageEventType MessageType<br />
		{<br />
			get{return m_type;}<br />
		}<br />
<br />
		/// <summary><br />
		/// Gets the status message<br />
		/// </summary><br />
		public string Message<br />
		{<br />
			get{return m_message;}<br />
		}<br />
<br />
	}<br />

and a event type enumerator:
<br />
[Serializable]<br />
	public enum FloatingStorageEventType<br />
	{<br />
		/// <summary><br />
		/// A text message<br />
		/// </summary><br />
		StatusText,<br />
		/// <summary><br />
		/// Error event<br />
		/// </summary><br />
		Error, <br />
		/// <summary><br />
		/// Warning event<br />
		/// </summary><br />
		Warning, <br />
		/// <summary><br />
		/// Storage startup<br />
		/// </summary><br />
		StorageStart,<br />
		/// <summary><br />
		/// Storage close<br />
		/// </summary><br />
		StorageStop,<br />
		/// <summary><br />
		/// Production start<br />
		/// </summary><br />
		ProductionStart,<br />
		/// <summary><br />
		/// Production stop<br />
		/// </summary><br />
		ProductionStop, <br />
	}<br />

The client connects to the server and starts to monitor for events:
<br />
try<br />
{<br />
BinaryClientFormatterSinkProvider clientProvider = new BinaryClientFormatterSinkProvider();<br />
BinaryServerFormatterSinkProvider serverProvider = new BinaryServerFormatterSinkProvider();<br />
serverProvider.TypeFilterLevel = System.Runtime.Serialization.Formatters.TypeFilterLevel.Full;<br />
                <br />
IDictionary props = new Hashtable();<br />
		<br />
props["port"] = 0;<br />
props["name"] = "StatusControl";<br />
props["typeFilterLevel"] = System.Runtime.Serialization.Formatters.TypeFilterLevel.Full;<br />
				<br />
m_chan = new TcpChannel(props, clientProvider, serverProvider);<br />
				<br />
ChannelServices.RegisterChannel(m_chan);<br />
				<br />
m_dist = (ProductionStatusControl.IDistributedControl) Activator.GetObject(Type.GetType("ProductionStatusControl.IDistributedControl, ProductionStatusControl"), "tcp://127.0.0.1:7889/IDistributedControl");<br />
m_dist.OnProductionStatusChanged += new ProductionStatusControl.ProductionStatusDelegate(m_dist_OnProductionStatusChanged);<br />
}<br />
catch( Exception ex )<br />
{<br />
System.Windows.Forms.MessageBox.Show( ex.ToString() );<br />
}<br />


The problem is that an exception is thrown in the
<br />
m_dist.OnProductionStatusChanged += new ProductionStatusControl.ProductionStatusDelegate(m_dist_OnProductionStatusChanged);<br />

part of the code.
<br />
		System.ArgumentException: Error binding to target method.<br />
<br />
															  Server stack trace: <br />
		at System.Delegate.InternalCreate(Object target, String method, Boolean ignoreCase)<br />
			at System.Delegate.CreateDelegate(Type type, Object target, String method)<br />
				at System.DelegateSerializationHolder.GetDelegate(DelegateEntry de)<br />
					at System.DelegateSerializationHolder.GetRealObject(StreamingContext context)<br />
						at System.Runtime.Serialization.ObjectManager.ResolveObjectReference(ObjectHolder holder)<br />
							at System.Runtime.Serialization.ObjectManager.DoFixups()<br />
								at System.Runtime.Serialization.Formatters.Binary.ObjectReader.Deserialize(HeaderHandler handler, __BinaryParser serParser, Boolean fCheck, IMethodCallMessage methodCallMessage)<br />
									at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(Stream serializationStream, HeaderHandler handler, Boolean fCheck, IMethodCallMessage methodCallMessage)<br />
										at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.UnsafeDeserialize(Stream serializationStream, HeaderHandler handler)<br />
											at System.Runtime.Remoting.Channels.CoreChannel.DeserializeBinaryRequestMessage(String objectUri, Stream inputStream, Boolean bStrictBinding, TypeFilterLevel securityLevel)<br />
												at System.Runtime.Remoting.Channels.BinaryServerFormatterSink.ProcessMessage(IServerChannelSinkStack sinkStack, IMessage requestMsg, ITransportHeaders requestHeaders, Stream requestStream, IMessage& responseMsg, ITransportHeaders& responseHeaders, Stream& responseStream)<br />
<br />
		Exception rethrown at [0]: <br />
		at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)<br />
			at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)<br />
		at ProductionStatusControl.IDistributedControl.add_OnProductionStatusChanged(ProductionStatusDelegate value)<br />
			at TAKAnalyzer.Form1.btnConnect_Click(Object sender, EventArgs e) in c:\vsprojects\csharp\takanalyzer\mainform.cs:line 242<br />


The exception dissaperes it I change the parameter in the delegate from EventMessage to string. The string is accepted but not the EventMessage. No exception is thrown in the server, only in the client.

Please advice, I am totally lost here.

Best Regards
Mikke
AnswerRe: Events over .Net Remoting Pin
Tom Larsen27-Oct-05 9:33
Tom Larsen27-Oct-05 9:33 
GeneralRe: Events over .Net Remoting Pin
Mikke_x27-Oct-05 9:57
Mikke_x27-Oct-05 9:57 
GeneralRe: Events over .Net Remoting Pin
Tom Larsen28-Oct-05 4:48
Tom Larsen28-Oct-05 4:48 
QuestionShared Classes Among Applications In a Single Project Pin
budidharma27-Oct-05 4:24
budidharma27-Oct-05 4:24 
AnswerRe: Shared Classes Among Applications In a Single Project Pin
Jeason Zhao27-Oct-05 4:30
Jeason Zhao27-Oct-05 4:30 
AnswerRe: Shared Classes Among Applications In a Single Project Pin
Matt Newman27-Oct-05 5:14
Matt Newman27-Oct-05 5:14 
GeneralRe: Shared Classes Among Applications In a Single Project Pin
budidharma27-Oct-05 6:11
budidharma27-Oct-05 6:11 
GeneralRe: Shared Classes Among Applications In a Single Project Pin
Rob Graham27-Oct-05 6:20
Rob Graham27-Oct-05 6:20 
AnswerRe: Shared Classes Among Applications In a Single Project Pin
Rob Graham27-Oct-05 6:14
Rob Graham27-Oct-05 6:14 
GeneralRe: Shared Classes Among Applications In a Single Project Pin
budidharma27-Oct-05 6:26
budidharma27-Oct-05 6:26 
QuestionAbout ADO.NET2.0 Exception:Capacity must be larger than 0 Pin
Jeason Zhao27-Oct-05 4:20
Jeason Zhao27-Oct-05 4:20 
Questionmanaged DirectX 9 Pin
faviochilo27-Oct-05 2:28
faviochilo27-Oct-05 2:28 
QuestionOut of Memory using DrawImage &amp; ImageAttributes Pin
mandrake_227-Oct-05 1:57
mandrake_227-Oct-05 1:57 
AnswerRe: Out of Memory using DrawImage &amp; ImageAttributes Pin
mandrake_227-Oct-05 4:01
mandrake_227-Oct-05 4:01 
Questionvalidators and javascript(confirm) Pin
ali bagheri27-Oct-05 1:45
ali bagheri27-Oct-05 1:45 
AnswerRe: validators and javascript(confirm) Pin
enjoycrack27-Oct-05 6:49
enjoycrack27-Oct-05 6:49 
QuestionHow to place multiple bitmaps into one picturebox ? Pin
Rashid.Mahmood27-Oct-05 1:36
Rashid.Mahmood27-Oct-05 1:36 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.