locked
Dynamically loaded Dll - Invoke Method - how to include an object in the parameters object[] RRS feed

  • Question

  • I am going to try asking this in as few words as possible to start with, and answer questions as details are requested.

    I am dynamically loading a dll, and calling a method using Invoke, and passing in an object[] as parameters.

    As long as the objects in the object[] are "primitives" (string, int, etc ) everything works fine.

    If I define my own class, however, the object needs to be cast back to its "real" class inside the dll, and that's where I get a problem.

    I get this error mesage:

    " Unable to cast object of type 'Key.DynamicFeature.CallbackMgr' to type 'Key.DynamicFeature.CallbackMgr'.   at DynamicFeatureParameterTester.KDF_ParamTester.Setup(Object[] parameters, String& reply)"

    the class Key.DynamicFeature.CallbackMgr is included in the dll project and the test project that dyamically loads the dll and makes the call.  It is included as source code, not as a reference to (yet another ) dll.

    My question is specifically about why the two "versions" of the class are not considered equivalent, and how can I get around that.  I have used the dynamically loaded dll technique enough in the past to feel reasonably confident that I am on solid ground there.

    --------------
    Finally, my end goal is to be able to enable the dynamically loaded dll to send information back to the calling app when certain events occur.  If there's a better way to do that, I'm not stubborn.






    Kirk Evans
    • Edited by Kirk Evans Wednesday, November 5, 2008 3:53 PM
    Wednesday, November 5, 2008 3:48 PM

Answers

  • The full type includes the assembly information in wich the type is contained.  The only workaround is to reference the same assembly that contains Key.DynamicFeature.CallbackMgr in your two projects.  If the current assemblies make this difficult; you might think about moving Key.DynamicFeature.CallbackMgr (and any other types that will be used this way) into a new assembly that would be referenced by both projects.
    http://www.peterRitchie.com/blog
    • Proposed as answer by Mattias Sjögren Thursday, November 6, 2008 1:00 PM
    • Marked as answer by Kirk Evans Thursday, November 6, 2008 3:09 PM
    Wednesday, November 5, 2008 4:14 PM

All replies

  • Likely the two binaries (the DLL and the code that uses it) referenc two different assemblies that contain Key.DynamicFeature.CallbackMgr.
    http://www.peterRitchie.com/blog
    Wednesday, November 5, 2008 3:52 PM
  • Peter,

    Thank you for the speedy response.  I *am* compiling two assemblies, one for the dll to be dynamically loaded, one for the WinForms app that dynamically loads the dll.

    Each assembly contains the source code file for the class.

    So, to a degree, I  understand why i am getting the "error" message - but I don't know what to do about it.

    Does my goal make sense to you, and if so, any advice on how to accomplish it?

    thanks again,
    Kirk


    Kirk Evans
    Wednesday, November 5, 2008 3:56 PM
  • The full type includes the assembly information in wich the type is contained.  The only workaround is to reference the same assembly that contains Key.DynamicFeature.CallbackMgr in your two projects.  If the current assemblies make this difficult; you might think about moving Key.DynamicFeature.CallbackMgr (and any other types that will be used this way) into a new assembly that would be referenced by both projects.
    http://www.peterRitchie.com/blog
    • Proposed as answer by Mattias Sjögren Thursday, November 6, 2008 1:00 PM
    • Marked as answer by Kirk Evans Thursday, November 6, 2008 3:09 PM
    Wednesday, November 5, 2008 4:14 PM
  • Thank you once again, Peter.

    I haven't tried it yet, but I see the wisdom of it - I'm (99.99%) sure that will work.  (I''m never 100% until I see it with my own eyes :) )



    I've lost count of the number of times that you've gotten me out of a jam, so if it helps you face your challenges though the day, know that your efforts are appreciated.





    Kirk Evans
    Wednesday, November 5, 2008 4:23 PM