注册事件会在客户端上抛出错误 [英] Register for event is throwing an error on the client
问题描述
我已经设置了一个服务器,2个客户端。我需要做的是在向服务器发送新消息时注册事件,以便客户端可以接收它。
服务器启动良好
客户端建立良好连接并且所有属性都是通过构造函数设置的,
现在当我在客户端注册一个事件时,我得到一个异常:
调用的目标抛出了异常。 br>
message = {"无法加载文件或程序集'AFCCIncChatAppClient,Version = 1.0.0.0,Culture = neutral,PublicKeyToken = null'或其依赖项之一。系统找不到指定的文件。":"AFCCIncChatAppClient,Version = 1.0.0.0,Culture = neutral,PublicKeyToken = null"}
source =" mscorlib"
堆栈跟踪=
服务器堆栈跟踪:
System.RuntimeMethodHandle._SerializationInvoke(Object target,SignatureStruct& declaringTypeSig,SerializationInfo info,StreamingContext context)
System.Runtime System.Sruntime.Serialization.ObjectManager.DoFixups()< > at System.Runtime.Serialization.Formatters.Binary.ObjectReader.Deserialize(HeaderHandler handler,__BinaryParser serParser,Boolean fCheck,Boolean isCrossAppDomain,IMethodCallMessage methodCallMessage)
at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(Stream serializationStream,HeaderHandler handler,Boolean fCheck,Boolean isCrossAppDomain,IMethodCallMessage methodCallMessage)
at System.Runtime.Remoting.Channels.CoreChannel .DeserializeBinaryRequestMessage(String objectUri,Stream inputStream,Boolean bStrictBinding,TypeFilterLevel securityLevel)
at System.Runtime.Remoting.Channels.BinaryServerFormatterSink.ProcessMessage(IServerChannelSinkStack sinkStack,IMessage requestMsg,ITransportHeaders requestHeaders,Stream requestStream,IMessage& responseMsg,ITransportHeaders& responseHeaders,Stream& responseStream)
I have set up a server, 2 clients. What I need to do is register for an event when ever a new message is sent to the server so that the client can receive it.
The server starts fine
The client makes a good connection and all propertes are set via the constructor,
Now when I get to registering for an event on the client I get an exception:
Exception has been thrown by the target of an invocation.
message = {"Could not load file or assembly 'AFCCIncChatAppClient, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.":"AFCCIncChatAppClient, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"}
source = "mscorlib"
stack trace=
Server stack trace:
at System.RuntimeMethodHandle._SerializationInvoke(Object target, SignatureStruct& declaringTypeSig, SerializationInfo info, StreamingContext context)
at System.Runtime.Serialization.ObjectManager.CompleteISerializableObject(Object obj, SerializationInfo info, StreamingContext context)
at System.Runtime.Serialization.ObjectManager.FixupSpecialObject(ObjectHolder holder)
at System.Runtime.Serialization.ObjectManager.DoFixups()
at System.Runtime.Serialization.Formatters.Binary.ObjectReader.Deserialize(HeaderHandler handler, __BinaryParser serParser, Boolean fCheck, Boolean isCrossAppDomain, IMethodCallMessage methodCallMessage)
at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(Stream serializationStream, HeaderHandler handler, Boolean fCheck, Boolean isCrossAppDomain, IMethodCallMessage methodCallMessage)
at System.Runtime.Remoting.Channels.CoreChannel.DeserializeBinaryRequestMessage(String objectUri, Stream inputStream, Boolean bStrictBinding, TypeFilterLevel securityLevel)
at System.Runtime.Remoting.Channels.BinaryServerFormatterSink.ProcessMessage(IServerChannelSinkStack sinkStack, IMessage requestMsg, ITransportHeaders requestHeaders, Stream requestStream, IMessage& responseMsg, ITransportHeaders& responseHeaders, Stream& responseStream)
在[0]处重新抛出异常:
在System.Runtime上的System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg,IMessage retMsg)中。 Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData,Int32 type)
at AFCCIncChatter.AFCCIncChatterWrapper.Chatter.add_NewMessageEvent(NewMessageDelegate value)
at AFCCIncChatAppClient.ChatClient.Main(String [] args)in C:\ Users \Administrator \ Document'\\Visual Studio 2008 \Projects\AFCCIncChatApp\AFCCIncChatAppClient\ChatClient.cs:line 41
at System.AppDomain._nExecuteAssembly(Assembly assembly,String [] args)
在Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
在System.Threading.ExecutionContext.Run(ExecutionContext executionContext,ContextCallback回调,对象状态)
在System.Threading.ThreadHelper.ThreadStart()
Exception rethrown at [0]:
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
at AFCCIncChatter.AFCCIncChatterWrapper.Chatter.add_NewMessageEvent(NewMessageDelegate value)
at AFCCIncChatAppClient.ChatClient.Main(String[] args) in C:\Users\Administrator\Documents\Visual Studio 2008\Projects\AFCCIncChatApp\AFCCIncChatAppClient\ChatClient.cs:line 41
at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
public abstract class UserBase : MarshalByRefObject
public abstract class UserBase : MarshalByRefObject
{
public 委托 void NewMessageDelegate ( string senderUserName, string 消息);
public delegate void NewMessageDelegate(string senderUserName, string message);
public abstract event NewMessageDelegate NewMessageEvent;
public abstract event NewMessageDelegate NewMessageEvent;
public string IPAddress { get ; set ; }
public string IPAddress { get; set; }
public < font color ="#0000ff"size = 2> string UserName { get ; set ; }
public string UserName { get; set; }
public < font color ="#2b91af"size = 2> UserImage UserImage { get ; set ; }
public UserImage UserImage { get; set; }
public < font color ="#0000ff"size = 2> abstract void SendNewMessage( 字符串 消息, string toUuserName);
public abstract void SendNewMessage(string message, string toUuserName);
public abstract void ReceiveNewMessage( string message, string fromUuserName);
public abstract void ReceiveNewMessage(string message, string fromUuserName);
}
< font color ="#0000ff"size = 2> 在客户端
static void Main( string [] args)
On the Client
static void Main(string[] args)
{
//选择沟通渠道与服务器
//select channel to communicate with server
TcpChannel channel;
TcpChannel channel;
System.Runtime.Remoting.Channels。 BinaryServerFormatterSinkProvider provider = new BinaryServerFormatterSinkProvider ();
System.Runtime.Remoting.Channels.BinaryServerFormatterSinkProvider provider = new BinaryServerFormatterSinkProvider();
provider.TypeFilterLevel = System .Runtime.Serialization.Formatters。 TypeFilterLevel 全部;
provider.TypeFilterLevel = System.Runtime.Serialization.Formatters.TypeFilterLevel.Full;
Hashtable props = new Hashtable ();
Hashtable props = new Hashtable();
频道= new TcpChannel (道具, null ,provider);
channel = new TcpChannel(props, null, provider);
ChannelServ ices .RegisterChannel(频道, false );
ChannelServices.RegisterChannel(channel, false);
_chatWrapper =
_chatWrapper =
( AFCCIncChatterWrapper ) RemotingServices .Connect
(AFCCIncChatterWrapper)RemotingServices.Connect
( typeof ( AFCCIncChatterWrapper ),
(typeof(AFCCIncChatterWrapper),
" tcp:// localhost:10001 / AFCCIncChatter" );
"tcp://localhost:10001/AFCCIncChatter");
_chatter =
_chatter =
_chatWrapper.ReturnNewChatter( " 111.111.111.111" , " clientUserName" );
_chatWrapper.ReturnNewChatter("111.111.111.111", "clientUserName");
_chatter .NewMessageEvent + = new AFCCIncChatterWrapper 。 UserBase 。 NewMessageDelegate (_ chatter_NewMessageEvent); < -------错误
_chatter.NewMessageEvent += new AFCCIncChatterWrapper.UserBase.NewMessageDelegate(_chatter_NewMessageEvent); <-------THE ERROR
_chatSession = _chatWrapper.ReturnNewChatSession(_chatter);
_chatSession = _chatWrapper.ReturnNewChatSession(_chatter);
//
//
}
static void _chatter_NewMessageEvent( string senderUserName, string <字体大小= 2>消息)
static void _chatter_NewMessageEvent(string senderUserName, string message)
{
throw new NotImplementedException ();
throw new NotImplementedException();
}
推荐答案
我认为您需要定义委托" AFCCIncChatterWrapper 。 UserBase 。 NewMessageDelegate "在一个强名称签名的图书馆里面。该库应安装在服务器端和客户端。
I think you need to define the delegate "AFCCIncChatterWrapper.UserBase.NewMessageDelegate" inside a library which is strong-name signed. This library should be installed on both the server and the client side.
这篇关于注册事件会在客户端上抛出错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!