Bonjour à tous,
J'ai un problème avec ce tuto : http://vincentlaine.developpez.com/t...pdomain/vbnet/

J'ai repris AssemblyLoader.dll ainsi qu'un grande partie du code :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
 
Imports System.Reflection
 
Public Class Loader
    Inherits MarshalByRefObject
    ' Methods
    Public Function CreateInstanceOf(ByVal index As Integer, ByVal typeName As String) As Object
        Return DirectCast(Me.assemblies.Item(index), Assembly).CreateInstance(typeName, True)
    End Function
 
    Public Sub Load(ByVal varassembly As String)
        Me.assemblies.Add([Assembly].Load(varassembly))
    End Sub
 
 
    ' Fields
    Private assemblies As ArrayList = New ArrayList
End Class
Les plugins que je voudrais chargé ont cet interface :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
Public Interface IPlugin
        ' Methods
        Sub Onload()
        Sub OnUnload()
 
        ' Properties
        ReadOnly Property Author As String
        ReadOnly Property Name As String
        ReadOnly Property Version As String
    End Interface
Pour les charger, j'utilise ces méthodes :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
Private loader As Loader
    Private pluginsDomain As AppDomain
    Private PluginList As List(Of IPlugin)

    Public Sub New()
        ' Cet appel est requis par le concepteur.
        InitializeComponent()

        ' Ajoutez une initialisation quelconque après l'appel InitializeComponent().
        PluginList = New List(Of IPlugin)
        loader = New Loader()
        LoadPlugins()
    End Sub


    Public Sub LoadPlugins()
        Dim path As String = Application.StartupPath & "/Plugins/"
        If Not Directory.Exists(Application.StartupPath & "/Plugins/") Then
            Directory.CreateDirectory(Application.StartupPath & "/Plugins/")
        End If
        ' Création du domaine d'application et chargement de la librairie de chargement
        Dim setup As AppDomainSetup
        setup = AppDomain.CurrentDomain.SetupInformation

        setup.PrivateBinPath = path
        setup.ShadowCopyFiles = "false"
        Me.pluginsDomain = AppDomain.CreateDomain("pluginsDomain", Nothing, setup)
        Me.loader = CType(Me.pluginsDomain.CreateInstanceFromAndUnwrap("AssemblyLoader.dll", "AssemblyLoader.Loader"), Loader)

        Dim dir As DirectoryInfo = New DirectoryInfo(Path)
        Dim iplugins As IPlugin
        Dim i As Integer = 0
        Dim file As FileInfo
        Dim type As String

        For Each file In dir.GetFiles("*.dll")
            type = file.Name.Replace(file.Extension, "")
            Me.loader.Load(type)
            iplugins = CType(Me.loader.CreateInstanceOf(i, type & "." & type), IPlugin)
            Me.PluginList.Add(iplugins)
        Next
    End Sub

Mon problème est que le cast ne veut pas se faire à la ligne coloré en rouge ci-dessus...


Merci d'avance pour votre aide