【问题标题】:Events and IPCServerChannel throws TargetInvocationException事件和 IPCServerChannel 抛出 TargetInvocationException
【发布时间】:2011-01-06 16:30:41
【问题描述】:

对于一些奇怪的问题,当我尝试使用事件和 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: 

【问题讨论】:

  • 除非您被困在 .NET 2.0 或更低版本,否则您不应该使用 Remoting。它已被 WCF 弃用。

标签: c# events remoting ipc


【解决方案1】:

无法加载文件或程序集“Vex 连接器客户端,...”

Remoting 应用程序的标准错误类型,它只是找不到程序集。确保它在那里,最好在与 exe 相同的目录中。如果您无法诊断无法找到程序集的原因,请使用 Fuslogvw.exe。


fuslogvw 跟踪清楚地显示了问题。服务器在自己的目录下寻找“vex connector client.exe”,Final Vex Connector/Vex Connector/Vex Connector Service/ 斌/调试/。但是文件不存在,它存储在Final Vex Connector/Vex Connector/Vex Connector Client/bin/Debug/

复制文件以解决问题。

如果您觉得服务器需要 client.exe 令人反感,则将它们共享的类放在单独的项目中。

【讨论】:

  • 我在这个程序中找不到任何问题。我有两个不同的应用程序:客户端和服务器。服务器编译是否也依赖于客户端?我需要处理事件的循环依赖吗?如何为此配置 Visual Studio?
  • 这是一个部署问题。任何包含 Connector 类的程序集都需要存在于服务器和客户端目录中。由于该类在两者中都使用。你可能想把它放在自己的程序集中。
  • 为什么我在调用事件时遇到这个问题?方法正常运行。我同意,这是一个部署问题,但在 Connector 类中?
  • 如果无法整理,请发布 fuslogvw.exe 跟踪。
  • 没有失败的绑定登录。服务器没有任何绑定的迹象。
猜你喜欢
  • 2014-08-17
  • 1970-01-01
  • 2016-01-06
  • 1970-01-01
  • 2011-11-10
  • 2022-12-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多