事件和 IPCServerChannel 抛出 TargetInitationException
对于一些奇怪的问题,当我尝试使用事件和 IPC 远程处理时遇到这些异常,这是什么意思?有人遇到过这个问题吗?
客户端
BinaryClientFormatterSinkProvider clientProvider = new BinaryClientFormatterSinkProvider();
IDictionary prop = new Hashtable();
prop["name"] = "remote";
prop["secure"] = true;
prop["priority"] = 1;
prop["tokenImpersonationLevel"] = TokenImpersonationLevel.Impersonation;
IpcClientChannel clientChannel = new IpcClientChannel(prop, clientProvider);
ChannelServices.RegisterChannel(clientChannel, true);
RemotingConfiguration.RegisterWellKnownClientType(typeof(Connector), "ipc://connector/connector");
Connector c = new Connector();
c.OnX += new Connector.X(c_OnX);
c.Connect();
服务器
BinaryServerFormatterSinkProvider serverProvider = new BinaryServerFormatterSinkProvider();
serverProvider.TypeFilterLevel = System.Runtime.Serialization.Formatters.TypeFilterLevel.Full;
IDictionary prop = new Hashtable();
prop["name"] = "remote";
prop["secure"] = true;
prop["priority"] = 1;
prop["portName"] = "connector";
prop["tokenImpersonationLevel"] = TokenImpersonationLevel.Impersonation;
prop["authorizedGroup"] = new SecurityIdentifier("S-1-1-0").Translate(typeof(NTAccount)).ToString(); /* Everyone or Todos =p - Sou amador, e dai ? */
// Create and register an IPC channel
IpcServerChannel serverChannel = new IpcServerChannel(prop, serverProvider);
ChannelServices.RegisterChannel(serverChannel, true);
// Expose an object
RemotingConfiguration.RegisterWellKnownServiceType(typeof(Connector), "connector", WellKnownObjectMode.Singleton);
异常
System.Reflection.TargetInvocationException was unhandled
Message=Exception has been thrown by the target of an invocation.
Source=mscorlib
StackTrace:
Server stack trace:
at System.RuntimeMethodHandle._SerializationInvoke(IRuntimeMethodInfo method, 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)
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 Vex_Connector_Service.Connector.add_OnX(X value)
at Vex_Connector_Client.Program.Main() in C:\Users\Vex\Desktop\Final Vex Connector\Vex Connector\Vex Connector Client\Program.cs:line 37
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException: System.IO.FileNotFoundException
Message=Could not load file or assembly 'Vex Connector Client, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. O sistema não pode encontrar o arquivo especificado.
Source=mscorlib
FileName=Vex Connector Client, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
FusionLog=WRN: Assembly binding logging is turned OFF.
To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1.
Note: There is some performance penalty associated with assembly bind failure logging.
To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog].
StackTrace:
at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
at System.Reflection.RuntimeAssembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection, Boolean suppressSecurityChecks)
at System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection)
at System.Reflection.Assembly.Load(String assemblyString)
at System.Runtime.Serialization.FormatterServices.LoadAssemblyFromString(String assemblyName)
at System.Reflection.MemberInfoSerializationHolder..ctor(SerializationInfo info, StreamingContext context)
InnerException:
For some bizarre problem when I try to use Events and IPC Remoting am getting these exceptions, which would be the point? Has anyone had this problem?
Client
BinaryClientFormatterSinkProvider clientProvider = new BinaryClientFormatterSinkProvider();
IDictionary prop = new Hashtable();
prop["name"] = "remote";
prop["secure"] = true;
prop["priority"] = 1;
prop["tokenImpersonationLevel"] = TokenImpersonationLevel.Impersonation;
IpcClientChannel clientChannel = new IpcClientChannel(prop, clientProvider);
ChannelServices.RegisterChannel(clientChannel, true);
RemotingConfiguration.RegisterWellKnownClientType(typeof(Connector), "ipc://connector/connector");
Connector c = new Connector();
c.OnX += new Connector.X(c_OnX);
c.Connect();
Server
BinaryServerFormatterSinkProvider serverProvider = new BinaryServerFormatterSinkProvider();
serverProvider.TypeFilterLevel = System.Runtime.Serialization.Formatters.TypeFilterLevel.Full;
IDictionary prop = new Hashtable();
prop["name"] = "remote";
prop["secure"] = true;
prop["priority"] = 1;
prop["portName"] = "connector";
prop["tokenImpersonationLevel"] = TokenImpersonationLevel.Impersonation;
prop["authorizedGroup"] = new SecurityIdentifier("S-1-1-0").Translate(typeof(NTAccount)).ToString(); /* Everyone or Todos =p - Sou amador, e dai ? */
// Create and register an IPC channel
IpcServerChannel serverChannel = new IpcServerChannel(prop, serverProvider);
ChannelServices.RegisterChannel(serverChannel, true);
// Expose an object
RemotingConfiguration.RegisterWellKnownServiceType(typeof(Connector), "connector", WellKnownObjectMode.Singleton);
Exception
System.Reflection.TargetInvocationException was unhandled
Message=Exception has been thrown by the target of an invocation.
Source=mscorlib
StackTrace:
Server stack trace:
at System.RuntimeMethodHandle._SerializationInvoke(IRuntimeMethodInfo method, 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)
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 Vex_Connector_Service.Connector.add_OnX(X value)
at Vex_Connector_Client.Program.Main() in C:\Users\Vex\Desktop\Final Vex Connector\Vex Connector\Vex Connector Client\Program.cs:line 37
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException: System.IO.FileNotFoundException
Message=Could not load file or assembly 'Vex Connector Client, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. O sistema não pode encontrar o arquivo especificado.
Source=mscorlib
FileName=Vex Connector Client, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
FusionLog=WRN: Assembly binding logging is turned OFF.
To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1.
Note: There is some performance penalty associated with assembly bind failure logging.
To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog].
StackTrace:
at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
at System.Reflection.RuntimeAssembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection, Boolean suppressSecurityChecks)
at System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection)
at System.Reflection.Assembly.Load(String assemblyString)
at System.Runtime.Serialization.FormatterServices.LoadAssemblyFromString(String assemblyName)
at System.Reflection.MemberInfoSerializationHolder..ctor(SerializationInfo info, StreamingContext context)
InnerException:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对于远程处理应用程序来说这是相当标准的错误,它只是找不到程序集。确保它在那里,最好与 exe 位于同一目录中。如果您无法诊断找不到程序集的原因,请使用 Fuslogvw.exe。
Fuslogvw 痕迹清楚地显示了问题。服务器正在其自己的目录中寻找“vex连接器client.exe”,Final Vex Connector/Vex Connector/Vex Connector Service/
bin/调试/.但该文件不存在,它存储在 Final Vex Connector/Vex Connector/Vex Connector Client/bin/Debug/
复制该文件以解决问题。
如果您觉得服务器需要 client.exe 令人不快,那么请将它们共享的类放在单独的项目中。
Pretty standard kind of error for a Remoting app, it just can't find the assembly. Make sure it's there, preferably in the same directory as the exe. Use Fuslogvw.exe if you have trouble diagnosing the reason it cannot find the assembly.
The fuslogvw traces show the problem clearly. The server is looking for "vex connector client.exe" in its own directory, Final Vex Connector/Vex Connector/Vex Connector Service/
bin/Debug/. But the file isn't there, it is stored in Final Vex Connector/Vex Connector/Vex Connector Client/bin/Debug/
Copy the file to fix the problem.
If you find it distasteful that the server needs the client.exe then put the classes they share in a separate project.