Bonjour,
Je suis en train de faire un programme qui utilise un "User Control" qui remplace le combobox en combobox ainsi qu'un bouton pour l'édition des valeurs
J'appelle le DLL dynamiquement et j'affiche une fenêtre pour l'édition de la valeur cela semble simple et facile a faire sauf que j'ai toujours une erreur lors de l'attribution de la valeur

Nom : 2020-09-24_11-01-08.jpg
Affichages : 127
Taille : 8,6 Ko
je n'arrive pas a trouvé comment je dois faire pour attribué une valeur a ma propriété selon le type de données
Lorsque l'usager clique sur le bouton a droite, celle-ci doit aller éditer la valeur dans la base de données et ce sont que des listes de configuration donc il sont tous pareil soit dans la BD cela ressemble a ceci
Code SQL : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
CREATE TABLE dbo.Attaches(
 ID INT autonumber
,Description VARCHAR(50)
)

J'ai une fonction pour savoir si la propriété existes dans la DLL

Code VB.NET : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
Private Function PropertyExists(ByVal assemblyObject As Object, ByVal objectt As Object, ByVal propertyy As String, value As Object) As Boolean
        Dim reallyExists As Boolean = False
        Dim type As Type = objectt.GetType()
        Dim info As System.Reflection.PropertyInfo = type.GetProperty(propertyy)
        If info IsNot Nothing Then
            reallyExists = SetValue(assemblyObject, info, propertyy, value)
        End If
        Return reallyExists
    End Function

J'ai un autre fonction qui attribut la valeur a la propriété trouvé
donc j'appelle cet procédure avec les informations suivante
modGlobal.SetValue(
assemblyObject <- La class sous la form d'un DLL charger dynamiquement
, info <- La propriété que je veux attribué la valeur
, propertyy <- PropertyInfo
, value) <- la nouvelle valeur soit un numéro unique ou un champs string ou un champs date
Code VB.NET : 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
Public Function SetValue(ByVal info As Object,
                        ByVal inputObject As Object,
                        ByVal propertyName As String,
                        ByVal propertyVal As Object) As Boolean
 
        Dim reallyExists As Boolean = False
        'find the property type
        Dim propertyType As Type = inputObject.PropertyType
 
        'Convert.ChangeType does not handle conversion to nullable types
        'if the property type is nullable, we need to get the underlying type of the property
        Dim targetType As Type = If(IsNullableType(inputObject.PropertyType), Nullable.GetUnderlyingType(inputObject.PropertyType), inputObject.PropertyType)
        Try
            If (Not inputObject Is Nothing AndAlso inputObject.CanWrite) Then
 
                inputObject.SetValue(info, Convert.ChangeType(propertyVal, targetType), Nothing)
                reallyExists = True
            End If
 
        Catch ex As Exception
            modGlobal.MessageErreur("Erreur d'attribution valeur non valide", "Erreur d'attribution valeur " & propertyName, "Erreur dans" & info.Module.FullyQualifiedName & vbCrLf & "  non valide " & vbCrLf & ex.Message & vbCrLf & ex.StackTrace)
            'Throw New NullReferenceException(ex.Message & vbCrLf & "Erreur d'attribution valeur " & propertyName & "  non valide ")
        End Try
 
        Return reallyExists
    End Function

J'ai aussi une fonction qui vérifie si le null est autorisé
Code VB.NET : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
Private Function IsNullableType(ByVal type As Type) As Boolean
        Return type.IsGenericType AndAlso type.GetGenericTypeDefinition().Equals(GetType(Nullable(Of)))
    End Function

Et finalement un fonction qui appelle le DLL en passant le nom de la DLL le nom de la classe ainsi qu'un objet contenant une DataTable qui contient ID et Description

Code VB.NET : 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
50
Public Function StartObjectList(ByVal AssemblyName As String, ByVal ClassName As String, ByVal StartUpObject As Object) As Boolean
        Dim bRetour As Boolean = False
        Try
            Dim Chemin As String = IO.Path.Combine(IO.Path.GetDirectoryName(Application.ExecutablePath), AssemblyName & ".dll")
            If IO.File.Exists(Chemin) Then
                Dim oAssembly As System.Reflection.Assembly = Reflection.Assembly.LoadFrom(Chemin)
                Dim oType As System.Type = oAssembly.GetType(ClassName)
                Dim oObject As System.Object
                oObject = Activator.CreateInstance(oType)
                oObject.Name = ClassName.Trim
 
                If Not oObject Is Nothing Then
                    If TypeOf oObject Is List(Of String) Then
                        For Each s As String In oObject
                           'pas terminer 
                        Next
                    Else
                        If TypeOf StartUpObject Is DataTable Then
                            Dim tbl As DataTable = CType(StartUpObject, DataTable)
 
                            For Each row As DataRow In tbl.Rows
                                For Each d As DataColumn In tbl.Columns
                                    If PropertyExists(oObject, d.ColumnName, row.Item(d.ColumnName)) Then
 
                                    End If
                                Next
                            Next
                        End If
                    End If
                End If
 
                oObject.Icon = Nothing
 
 
                oObject.ShowDialog()
                bRetour = True
            Else
                Using frm As New CustomMessageError("Erreur de chargement de DLL", "Fichier inexistant et objet non activé", "Le fichier manquant := " & Chemin)
                    frm.ShowDialog()
                End Using
            End If
 
 
        Catch ex As Exception
            Using frm As New CustomMessageError("Erreur de chargement de DLL", ex.Message, ex.Message & vbCrLf & ex.StackTrace)
                frm.ShowDialog()
            End Using
        End Try
        Return bRetour
    End Function

Je n'arrive pas a faire fonctionner l'appelle au DLL je suis en mesure d'appeler certaine Forms mais pas attribué dynamiquement la valeur a une propriété

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
Le membre public 'Module' du type 'RuntimeAssembly' est introuvable.
   à Microsoft.VisualBasic.CompilerServices.Symbols.Container.GetMembers(String& MemberName, Boolean ReportErrors)
   à Microsoft.VisualBasic.CompilerServices.NewLateBinding.ObjectLateGet(Object Instance, Type Type, String MemberName, Object[] Arguments, String[] ArgumentNames, Type[] TypeArguments, Boolean[] CopyBack)
   à Microsoft.VisualBasic.CompilerServices.NewLateBinding.LateGet(Object Instance, Type Type, String MemberName, Object[] Arguments, String[] ArgumentNames, Type[] TypeArguments, Boolean[] CopyBack)
   à Repartiteur.Utility.modGlobal.SetValue(Object info, Object inputObject, String propertyName, Object propertyVal) dans ..Utility\modGlobal.vb:ligne 181
   à Repartiteur.Utility.modGlobal.PropertyExists(Object assemblyObject, Object objectt, String propertyy, Object value) dans ..Utility\modGlobal.vb:ligne 159
   à Repartiteur.Utility.modGlobal.StartObjectList(String AssemblyName, String ClassName, Object StartUpObject) dans ..Utility\modGlobal.vb:ligne 218