我正在尝试制作一个进程外的.Net DLL;使用示例代码,我可以制作一个进程外的 COM DLL。但是,我在实现事件处理时遇到了一些问题。
根据代码,组件公开以下事件:
Public Event FloatPropertyChanging(ByVal NewValue As Single, ByRef Cancel As Boolean)
在 VB.Net 表单应用程序中处理该事件会引发异常。以下是详细信息:
Dim tempObj As New VBServicedComponent.SimpleObject()
AddHandler tempObj.FloatPropertyChanging, AddressOf FloatPropertyChangingEventHandler // **Throws Exception!!!**
tempObj.FloatProperty = 4
异常详情:
System.Reflection.TargetInvocationException:-
Exception has been thrown by the target of an invocation
堆栈跟踪:
在 System.RuntimeMethodHandle.SerializationInvoke(IRuntimeMethodInfo 方法,对象目标,SerializationInfo 信息,StreamingContext 和上下文)在 System.Runtime.Serialization.ObjectManager.CompleteISerializableObject(对象 obj,SerializationInfo 信息,StreamingContext 上下文)在 System.Runtime.Serialization.ObjectManager.FixupSpecialObject( ObjectHolder holder)在 System.Runtime.Serialization.Formatters.Binary.ObjectReader.Deserialize(HeaderHandler handler, __BinaryParser serParser, Boolean fCheck, Boolean isCrossAppDomain, IMethodCallMessage methodCallMessage)在 System.EnterpriseServices 的 System.Runtime.Serialization.ObjectManager.DoFixups()。 System.EnterpriseServices.ComponentServices.ConvertToMessage(String s, Object tp) 在 System.EnterpriseServices 的 ComponentSerializer.UnmarshalFromBuffer(Byte[] b, Object tp)。ServicedComponent.RemoteDispatchHelper(String s, Boolean& failed) 在 System.EnterpriseServices.ServicedComponent.System.EnterpriseServices.IRemoteDispatch.RemoteDispatchNotAutoDone(String s) 在 System.EnterpriseServices.IRemoteDispatch.RemoteDispatchNotAutoDone(String s) 在 System.EnterpriseServices.RemoteServicedComponent.Invoke(IMessage reqMsg) at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type) at VBServicedComponent.SimpleObject.add_FloatPropertyChanging(FloatPropertyChangingEventHandler obj) at TestApp.modMain.Main() in D:\Meridia\MeridiaAPI\COMPlusServices\TestApp \Module1.vb:第 34 行RemoteDispatchNotAutoDone(String s) at System.EnterpriseServices.IRemoteDispatch.RemoteDispatchNotAutoDone(String s) at System.EnterpriseServices.RemoteServicedComponentProxy.Invoke(IMessage reqMsg) at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type) at VBServicedComponent .SimpleObject.add_FloatPropertyChanging(FloatPropertyChangingEventHandler obj) 在 D:\Meridia\MeridiaAPI\COMPlusServices\TestApp\Module1.vb:line 34 中的 TestApp.modMain.Main()RemoteDispatchNotAutoDone(String s) at System.EnterpriseServices.IRemoteDispatch.RemoteDispatchNotAutoDone(String s) at System.EnterpriseServices.RemoteServicedComponentProxy.Invoke(IMessage reqMsg) at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type) at VBServicedComponent .SimpleObject.add_FloatPropertyChanging(FloatPropertyChangingEventHandler obj) 在 D:\Meridia\MeridiaAPI\COMPlusServices\TestApp\Module1.vb:line 34 中的 TestApp.modMain.Main()add_FloatPropertyChanging(FloatPropertyChangingEventHandler obj) 在 D:\Meridia\MeridiaAPI\COMPlusServices\TestApp\Module1.vb:line 34 中的 TestApp.modMain.Main()add_FloatPropertyChanging(FloatPropertyChangingEventHandler obj) 在 D:\Meridia\MeridiaAPI\COMPlusServices\TestApp\Module1.vb:line 34 中的 TestApp.modMain.Main()
内部异常:
Could not load file or assembly 'TestApp, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.":"TestApp, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
堆栈跟踪:
在 System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark & stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblySecurityRef, Evidence assembly , RuntimeAssembly reqAssembly, StackCrawlMark & stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean for Introspection, Boolean suppressSecurityChecks) at System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark & stackMark, IntPtr pPrivHostBinder, Boolean for Introspection) at System.Reflection.Runtime. InternalLoad(String assemblyString, 证据 assemblySecurity,StackCrawlMark& stackMark, Boolean for Introspection) at System.Reflection.Assembly.Load(String assemblyString) at System.Runtime.Serialization.FormatterServices.LoadAssemblyFromString(String assemblyName) at System.Reflection.MemberInfoSerializationHolder..ctor(SerializationInfo info, StreamingContext context)
在处理事件时,我在 TestApp 结束时有什么遗漏吗?如果是,那么处理此类事件的正确方法是什么?
提前致谢。