none
PlugIn developlment, Getting error, InvalidCastException RRS feed

  • Question

  • Hey

    I am bit frustrated, because I am not able to handle my Error.

    I have developed a Plugin and now, I am getting an error with the following code:

    Dim locAssembly As Assembly = Assembly.LoadFrom(locFile)
                    Dim locTypes() As Type = locAssembly.GetTypes
                    For Each locType As Type In locTypes
                        Dim locInterfaces() As Type = locType.GetInterfaces
                        For Each locInterface As Type In locInterfaces
                            If locInterface.FullName = "IntelliSoftPlugin.GlasListenPlugin" Then
                                '-- Load the object
                                Dim locObject As Object = locAssembly.CreateInstance(locType.FullName)
    
                                Dim locPlugIn = CType(locObject, IntelliSoftPlugin.GlasListenPlugin)
                                myPlugIns.Add(locPlugIn)
                                SetComboBox(locPlugIn.GetCompanyName, locPlugIn)
                                '    End If
                                'End If
                            End If
    
                        Next
                    Next

    I am getting the following error:

    System.InvalidCastException: 'The Object of type "ISEssilor.Startup" can not be casted to "IntelliSoftPlugin.GlasListenPlugin"'

    (The error is translated from the german version...)

    The "Type" ISEssilor.Startup" is: The filename "ISEssilor" from the used dll file and "Startup" ist the class, which has implemented the "IntelliSoftPlugin.GlasListenPlugin" Interface.

    And the error is raised at the code line: "Dim locPlugIn = CType(locObject, IntelliSoftPlugin.GlasListenPlugin)"

    What does not make any sense, because I first check, if the Interface is there (what it is) and then, when I try to cast it, I am running into this error. 

    Could someone of you please help me out of this mystery.

    THX

    Saturday, April 7, 2018 5:15 PM

Answers

  • 13 hours later...

    Thx to this post: Stackoverflow

    I found out, what the problem is/was

    The class library, which holds the PlugIn definition ("GlasListenPlugin") was copied to the folder, where the .dll's get read to check it.

    I don't know why, but it seems that the main application reads the referenced .dll and when in the same folder, then the plugin reads the .dll from the folder, where it is in.

    Just deleting the plugin .dll from the folder where all plugins are in did the job and everything works as wanted.


    • Marked as answer by Zero-G. _ Sunday, April 8, 2018 6:29 AM
    • Edited by Zero-G. _ Sunday, April 8, 2018 6:29 AM
    Sunday, April 8, 2018 6:28 AM

All replies

  • Make sure that your program and the Plug-In use the same assembly (same version) that contains GlasListenPlugin.


    • Edited by Viorel_MVP Saturday, April 7, 2018 5:45 PM
    Saturday, April 7, 2018 5:44 PM
  • Hey

    THX. Yes, they use both the same assembly. 

    But still the same issue

    Saturday, April 7, 2018 6:02 PM
  • Maybe use a TextBox or RichTextBox to display the different Local Interfaces properties to see what may be inaccurate or misrepresented so you can display all to see what is amiss before moving further.

    La vida loca

    Sunday, April 8, 2018 2:18 AM
  • 13 hours later...

    Thx to this post: Stackoverflow

    I found out, what the problem is/was

    The class library, which holds the PlugIn definition ("GlasListenPlugin") was copied to the folder, where the .dll's get read to check it.

    I don't know why, but it seems that the main application reads the referenced .dll and when in the same folder, then the plugin reads the .dll from the folder, where it is in.

    Just deleting the plugin .dll from the folder where all plugins are in did the job and everything works as wanted.


    • Marked as answer by Zero-G. _ Sunday, April 8, 2018 6:29 AM
    • Edited by Zero-G. _ Sunday, April 8, 2018 6:29 AM
    Sunday, April 8, 2018 6:28 AM