none
TargetException while raising COM event for interop RRS feed

  • Question

  • Hi experts,

    I've one DLL loaded in two Internet Explorer Windows. While loading the first one, a singleton is created. This singleton raises COM events, which are received by JavaScript in the Internet Explorer windows. This works fine and both IE windows are getting the events. The whole scenario works on my development machine. After deploying everything to a production machine, I get a TargetException (the object does not match the target type) when raising the COM event, but only when a function in the singleton is called from the second IE window. When I call a function from singleton instance from the first IE window everything works fine and I receive the events. I am completely lost because it works on my dev machine.

    My event is defined in an interface, however the delegate is created within the singleton class.

    The event definition:

      [Guid("6FA477D9-85C7-4bf3-9D53-F5440AD7164F")]
    
      [InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
    
      [ComVisible(true)]
    
      public interface IOcsExposedEvents
    
      {
    
    
        void CallStatusEvent(string message);
    
      }

    The function definition raising the event :

    [Guid("3F088DF3-2C22-4b81-8D28-68547665E706"),
    InterfaceType(ComInterfaceType.InterfaceIsDual),
    ComVisible(true)]
    
    public interface IOcsIntegrator
    
    {
    
    
      int call(string sip_uri);
    
    }
    
    

    My event delegate (defined in the singleton class):

    public delegate void CallStatusDelegate(string message);
    
    
    public event CallStatusDelegate CallStatusEvent;

     

    And finally raising the event:

    public int call(string sip_uri)
    
    {
      _callStatus = CallStatus.disconnected;
    
      CallStatusEvent(_callStatus.ToString());
    }

     

     

    Any help is really appreciated!

    Monday, October 25, 2010 3:04 PM

All replies

  • Is this running on a server? I think the singleton is the issue. I suggest removing it, you don't need it nor can it possibly create a single instance on a server (unless you have some trick code in there). You're likely ending up with more than one instance of your object.  
    Wednesday, October 27, 2010 2:33 AM
  • Thanks for reply!

     

    The code is running in a compiled DLL, which is loaded by IE on a client machine. A second DLL is implementing the singleton (code above) and is used by the other DLL in IE. I need to make sure that only one instance is available in the IE process. (otherwise the client is logged in multiple times). That is the reason why I'm using the singleton in the first place. I limited the IE to one process only and the code is working fine on the dev machine. What is bugging me is that the code does not work on the production machine.

    Wednesday, October 27, 2010 6:35 AM
  • Here is my logfile out put of the exception:

     

    15:53:57::ProcID 5168 :: Debug        Stack Trace:    at System.RuntimeType.InvokeDispMethod(String name, BindingFlags invokeAttr, Object target, Object[] args, Boolean[] byrefModifiers, Int32 culture, String[] namedParameters)
       at System.RuntimeType.InvokeMember(String name, BindingFlags bindingFlags, Binder binder, Object target, Object[] providedArgs, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParams)
       at System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData)
       at OcsIntegrationSlimClient.IOcsExposedSlimClientEvents.CallStatusChangedEvent(String message)
       at OcsIntegrationSlimClient.SlimClient.CallStatusChangedDelegate.Invoke(String status)
       at OcsIntegrationSlimClient.SlimClient.OnCallStatusChanged(String message) in C:\Users\DE5ECENT\Documents\Visual Studio 2008\Projects\OCSIntegrationLibrary\OcsIntegrationSlimClient\SlimClient.cs:line 229
       at OcsIntegrationServer.Server.CallStatusChangedDelegate.Invoke(String message)
       at OcsIntegrationServer.Server.OnCallStatusChangedHandler_l(String message) in C:\Users\DE5ECENT\Documents\Visual Studio 2008\Projects\OCSIntegrationLibrary\OCSIntegrationLibrary\Server.cs:line 303
       at OCSIntegrationLibrary.StatusNotifier.onCallStatusChanged(String callStatus) in C:\Users\DE5ECENT\Documents\Visual Studio 2008\Projects\OCSIntegrationLibrary\OCSIntegrationLibrary\StatusNotifier.cs:line 58
    15:53:57::ProcID 5168 :: Debug                  Source: mscorlib
    15:53:57::ProcID 5168 :: Debug                  Message: Object does not match target type.
    15:53:57::ProcID 5168 :: Debug                  Data: System.Collections.ListDictionaryInternal
    15:53:57::ProcID 5168 :: Debug                  Target Site: System.Object InvokeDispMethod(System.String, System.Reflection.BindingFlags, System.Object, System.Object[], Boolean[], Int32, System.String[])
    15:53:57::ProcID 5168 :: Debug                  Exception Type: System.Reflection.TargetException
    15:53:57::ProcID 5168 :: Debug                  Base Exception: System.Reflection.TargetException: Object does not match target type.
       at System.RuntimeType.InvokeDispMethod(String name, BindingFlags invokeAttr, Object target, Object[] args, Boolean[] byrefModifiers, Int32 culture, String[] namedParameters)
       at System.RuntimeType.InvokeMember(String name, BindingFlags bindingFlags, Binder binder, Object target, Object[] providedArgs, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParams)
       at System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData)
       at OcsIntegrationSlimClient.IOcsExposedSlimClientEvents.CallStatusChangedEvent(String message)
       at OcsIntegrationSlimClient.SlimClient.CallStatusChangedDelegate.Invoke(String status)
       at OcsIntegrationSlimClient.SlimClient.OnCallStatusChanged(String message) in C:\Users\DE5ECENT\Documents\Visual Studio 2008\Projects\OCSIntegrationLibrary\OcsIntegrationSlimClient\SlimClient.cs:line 229
       at OcsIntegrationServer.Server.CallStatusChangedDelegate.Invoke(String message)
       at OcsIntegrationServer.Server.OnCallStatusChangedHandler_l(String message) in C:\Users\DE5ECENT\Documents\Visual Studio 2008\Projects\OCSIntegrationLibrary\OCSIntegrationLibrary\Server.cs:line 303
       at OCSIntegrationLibrary.StatusNotifier.onCallStatusChanged(String callStatus) in C:\Users\DE5ECENT\Documents\Visual Studio 2008\Projects\OCSIntegrationLibrary\OCSIntegrationLibrary\StatusNotifier.cs:line 58
    15:53:57::ProcID 5168 :: Debug                  Inner Exception:

     

     

    Note: The function fireing the event is now StatusNotifier::onCallStatusChanged()

    But the syntax is the same like above.

     

    Any help is really appreciated!

    Monday, November 8, 2010 5:10 PM
  • Did you ever find a solution to your problem? I think we are seeing the same thing in a production environment, but not in dev. It is really difficult to reproduce, so hard to troubleshoot.

    We are running an ActiveX control inside of IE, and we see this happen when raising an event.

    Monday, July 1, 2013 2:59 AM
  • Hi ding3r

    since the problem has been solved long time ago I only remember some details about the solution. As far as I remember the registration of the COM events in combination with some IE security settings had caused the trouble. 

    In our prod environment the security restrictions had been harder causing the described problem.

    Kind regards

    Monday, July 1, 2013 8:53 AM
  • Any news?

    We have similar problem. We have a COM ActiveX developed in C# (Windows forms).

    In development environment we call an event OnActionCompleted(shot code, string message) and the event is handled correctly by IE.

    IN a production environment the same code thrown an TargetException: Object does not match target type event dispatcher.

    Any idea?


    • Edited by Paolo Mosna Monday, July 22, 2013 7:07 PM typing error
    Monday, July 22, 2013 7:06 PM
  • Hi Comandertwo

    I would like to know if you remember what did you do to resolve this issue.

    It works perfectly on my machine, but, in another environment, it fails, i got the same probleme: 

    System.Reflection.TargetException: Object does not match target type.
       at System.RuntimeType.InvokeDispMethod

    Please, let us know what did you do..

    Thanks and regards.

    Tuesday, August 27, 2013 9:45 PM