我已经与远程服务器建立了通信。远程服务器暴露了一个事件。当我尝试订阅该事件时,我得到以下堆栈跟踪的异常
[System.Reflection.TargetInvocationException]
= {"Exception has been thrown by the target of an invocation."}
[System.Reflection.TargetInvocationException]
= {"Exception has been thrown by the target of an invocation."}
at System.Reflection.Assembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, Assembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection)
at System.Reflection.Assembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, Assembly locationHint, StackCrawlMark& stackMark,
Boolean throwOnFileNotFound, Boolean forIntrospection)
at System.Reflection.Assembly.InternalLoad(AssemblyName assemblyRef, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection)
at System.Reflection.Assembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection)\r\n
at System.Reflection.Assembly.Load(String assemblyString)
at System.Reflection.MemberInfoSerializationHolder..ctor(SerializationInfo info, StreamingContext context)
StackTrace
Server stack trace:
at System.RuntimeMethodHandle._SerializationInvoke(Object target, SignatureStruct& declaringTypeSig, SerializationInfo info, StreamingContext context)
at System.Reflection.RuntimeConstructorInfo.SerializationInvoke(Object target, 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)
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 Mycode.Method(EventHandler value)
at Mysource.Initialize()
我的代码块如下:远程服务器的配置如下 //code
TurnOffRemotingExceptionFiltering();
BinaryClientFormatterSinkProvider^ clientProvider = nullptr;
BinaryServerFormatterSinkProvider^ serverProvider = gcnew aryServerFormatterSinkProvider();
serverProvider->TypeFilterLevel = TypeFilterLevel::Full;
System::Collections::IDictionary^ props = gcnew Hashtable();
props["port"] = port;
String^ guid = System::Guid::NewGuid().ToString();
props["typeFilterLevel"] = TypeFilterLevel::Full;
//TcpChannel
channel = gcnew TcpChannel(props, clientProvider, serverProvider);
ChannelServices::RegisterChannel(channel, false);
props["name"] = guid;
void RemoteConnectionManager::TurnOffRemotingExceptionFiltering()
{
// Gets the assembly in which the 'System.Runtime.Remoting.RemotingConfiguration' is defined.
Assembly^ remoting = Assembly::GetAssembly(RemotingConfiguration::typeid);
// Gets the Type object of 'System.Runtime.Remoting.CustomErrorsModes' from assembly instance.
Type^ customErrorsModes = remoting->GetType("System.Runtime.Remoting.CustomErrorsModes");
// Gets the Type object of 'System.Runtime.Remoting.RemotingConfigHandler' from assembly instance.
Type^ remotingConfigHandler = remoting->GetType("System.Runtime.Remoting.RemotingConfigHandler");
// Gets details of '_errorMode' field.'_errorMode' indicates whether the server channels in
// this application domain return filtered or complete exception information to local or remote callers.
FieldInfo^ errorMode = remotingConfigHandler->GetField("_errorMode",
BindingFlags::Static | BindingFlags::NonPublic);
// Gets details of 'Off' field.'System.Runtime.Remoting.CustomErrorsModes' is an Enumeration
FieldInfo^ mode = customErrorsModes->GetField("Off");
// Sets "Off" to get to get complete exception information
// from server channels to to local or remote callers.
errorMode->SetValue(nullptr, mode->GetValue(nullptr));
}