0

I'm trying to make an out of process .Net DLL; using the sample code, I'm able to make an out of process COM DLL. However, I'm facing some issues while implementing event handling.

As per code, following event is exposed by the component:

Public Event FloatPropertyChanging(ByVal NewValue As Single, ByRef Cancel As Boolean)

Handling that event in a VB.Net Form application throws an exception. Below are the details:

Dim tempObj As New VBServicedComponent.SimpleObject()

AddHandler tempObj.FloatPropertyChanging, AddressOf FloatPropertyChangingEventHandler // **Throws Exception!!!**
tempObj.FloatProperty = 4

Exception Details:

System.Reflection.TargetInvocationException:-
Exception has been thrown by the target of an invocation

Stack Trace:

at System.RuntimeMethodHandle.SerializationInvoke(IRuntimeMethodInfo method, 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.EnterpriseServices.ComponentSerializer.UnmarshalFromBuffer(Byte[] b, Object tp) at System.EnterpriseServices.ComponentServices.ConvertToMessage(String s, Object tp) at System.EnterpriseServices.ServicedComponent.RemoteDispatchHelper(String s, Boolean& failed) at System.EnterpriseServices.ServicedComponent.System.EnterpriseServices.IRemoteDispatch.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) at TestApp.modMain.Main() in D:\Meridia\MeridiaAPI\COMPlusServices\TestApp\Module1.vb:line 34

Inner Exception:

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

Stack Trace:

at 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 assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) at System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean forIntrospection) 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)

Is there anything I'm missing at TestApp ends while handling event? If yes, what would be a proper way handle such event?

Thanks in advance.

Azaz ul Haq
  • 1,635
  • 2
  • 18
  • 46
  • It is a very plain file-not-found error. Use Fuslogvw.exe to diagnose assembly resolution problems. It probably looks in the completely wrong directory for the file. – Hans Passant Apr 13 '16 at 10:24
  • Hans, thanks for quick reply. I've tried fuslogvw.exe, however, it does not log any exception text when I run TestApp.exe which throws exception. I'm sure the Fusion log viewer is properly setup. Aprt from that, interestingly as per runtime exception, the file or assembly which seems to be missing is actually the currently executing assembly i.e. TestAop.exe. – Azaz ul Haq Apr 13 '16 at 11:17
  • Start Fuslogvw.exe from an elevated command prompt. Note the discrepancy between your comment and the question, you started talking about a DLL but now mention an EXE. You cannot have a DLL and an EXE both called TestApp, that will always fail. – Hans Passant Apr 13 '16 at 11:25
  • Sorry for creating confusion. Let me clarify, I've a COM DLL(out of process) named "VBServicedComponent".dll which is being used/consumed by a Form Application named "TestApp".exe. So DLL and EXE do not share same name. Now in TestApp, I'm getting an exception when I use AddHander statement (as mentioned above). – Azaz ul Haq Apr 13 '16 at 11:55
  • I think you need to assume that it is *actually* VBServicedComponent.dll that is getting loaded to provide the component, not TestApp.exe. Then hoping that another file like TestApp.exe can be found is idle hope, the CLR won't look in the same directory. As Fuslogvw would show if you could get it to work. The workaround is to create a single DLL with no dependencies or use the GAC or subscribe the AppDomain.CurrentDomain.AssemblyResolve event in the constructor of the "main" .NET class so you can help the CLR find the file(s). – Hans Passant Apr 13 '16 at 12:08
  • Hans, your workaround worked, thanks! Placing both the library(DLL) and TestApp.exe in GAC resolved the issue. However, I'm just wondering if is it possible to this could be achieved with GAC oriented solution? – Azaz ul Haq Apr 15 '16 at 10:30

0 Answers0