Bonjour,

Voilà quelques jours que je me casse la tête, et peut-être ai-je mal lu tous les posts que j'ai pu trouvé sur internet, mais la je sèche.

Je souhaite charger une dll (un plugin .net) au lancement de mon programme, dans une appdomain différente de celle ou est lancé le thread principal, pour pouvoir ensuite la supprimer lorsque je décharge l'appdomain.
Mais impossible à supprimer ce fichier dll, étant toujours verrouillé par je ne sais quoi...

Voici l'extrait de code, merci pour votre soutien :

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
44
45
46
47
48
49
 
        Try
            Dim pathkd As String = Path.Combine(Application.StartupPath, "kd.sdk.dll")
 
            'write dll on Application.StartupPath
            If decompressdll(pathkd, My.Resources.kd_sdk) Then
                temp_clean.Add(pathkd)
 
                'Create the plug-in AppDomain setup.
                Dim appDomSetup As AppDomainSetup = New AppDomainSetup With {
                    .ApplicationName = "KD.SDK",
                    .ApplicationBase = AppDomain.CurrentDomain.BaseDirectory,
                    .LoaderOptimization = LoaderOptimization.MultiDomainHost,
                    .ShadowCopyFiles = "true"
                    }
 
                'Create the plug-in AppDomain with the setup.
                appDom = AppDomain.CreateDomain(appDomSetup.ApplicationName, Nothing, appDomSetup)
 
                'Execute the loader in the plug-in AppDomain's context.
                appDom.DoCallBack(New CrossAppDomainDelegate(AddressOf PluginCallback))
                AppDomain.Unload(appDom)
                appDom = Nothing
                File.Delete(Path.Combine(Application.StartupPath, "kd.sdk.dll"))
                Return True
            Else
                Throw (New Exception("decompress dll => false"))
            End If
        Catch ex As Exception
            temp_log.Add(Now.ToString & " Error: " & ex.Message)
            Return False
        End Try
 
 
Public Sub PluginCallback()
        Try
            'Load the plug-in.
            Dim pluginDLL As Reflection.Assembly = Reflection.Assembly.Load("kd.sdk")
            'Create the instance of the plug-in And call the interface methods.
            Dim myType As Type = pluginDLL.GetType("KD.SDK.Appli", True, True)
            oAppli = Activator.CreateInstance(myType, IO.Path.GetFileName(SpaceFileName))
 
            If Not oAppli.sessionid > 1 Then
                Throw (New Exception("Session error => 0"))
            End If
        Catch ex As Exception
            temp_log.Add(Now.ToString & " Error: " & ex.Message)
        End Try
    End Sub
MErci à vous