[COLOR=#008080]Assembly[/COLOR][SIZE=2] assembly = [/SIZE][SIZE=2][COLOR=#008080]Assembly[/COLOR][/SIZE][SIZE=2].LoadFrom( ASSEMBLY_NAME );
[/SIZE][SIZE=2][COLOR=#008000] // On obtient la classe.
[/COLOR][/SIZE][SIZE=2][COLOR=#008080] Type[/COLOR][/SIZE][SIZE=2] type = assembly.GetType( CLASS_NAME );
[/SIZE][SIZE=2][COLOR=#008000] // On obtient la méthode.
[/COLOR][/SIZE][SIZE=2][COLOR=#008080] MethodInfo[/COLOR][/SIZE][SIZE=2] method = type.GetMethod( METHOD_NAME );
[/SIZE][SIZE=2][COLOR=#008000] // On créer l'objet.
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff] object[/COLOR][/SIZE][SIZE=2] target = [/SIZE][SIZE=2][COLOR=#008080]Activator[/COLOR][/SIZE][SIZE=2].CreateInstance( type );[/SIZE]
[SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]public [/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]object[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] objet = [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]null[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2];[/SIZE]
[SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]public [/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]bool[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] Importer([/SIZE][SIZE=2][COLOR=#2b91af][SIZE=2][COLOR=#2b91af]String[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] Fichier,[/SIZE][SIZE=2][COLOR=#2b91af][SIZE=2][COLOR=#2b91af]String[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] Class)[/SIZE]
[SIZE=2]{[/SIZE]
[SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff] try[/COLOR][/SIZE]
[/COLOR][/SIZE][SIZE=2] {[/SIZE]
[SIZE=2][COLOR=#008000][SIZE=2][COLOR=#008000]// On Charge l'assembly.[/COLOR][/SIZE]
[/COLOR][/SIZE][SIZE=2][COLOR=#2b91af][SIZE=2][COLOR=#2b91af] Assembly[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] a = [/SIZE][SIZE=2][COLOR=#2b91af][SIZE=2][COLOR=#2b91af]Assembly[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2].LoadFrom(Fichier);[/SIZE]
[SIZE=2][COLOR=#008000][SIZE=2][COLOR=#008000]//Les classes:[/COLOR][/SIZE]
[SIZE=2][COLOR=#008000]// Type[] type = a.GetTypes();[/COLOR][/SIZE]
[/COLOR][/SIZE][SIZE=2][COLOR=#008000][SIZE=2][COLOR=#008000]// On obtient la classe.[/COLOR][/SIZE]
[/COLOR][/SIZE][SIZE=2][COLOR=#2b91af][SIZE=2][COLOR=#2b91af] Type[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] type = a.GetType(Class);[/SIZE]
[SIZE=2][COLOR=#008000][SIZE=2][COLOR=#008000]// On obtient la mthode.[/COLOR][/SIZE]
[/COLOR][/SIZE][SIZE=2] objet = [/SIZE][SIZE=2][COLOR=#2b91af][SIZE=2][COLOR=#2b91af]Activator[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2].CreateInstance(type);[/SIZE]
[SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff] return [/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]true[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2];[/SIZE]
[SIZE=2] }[/SIZE]
[SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]catch[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] ([/SIZE][SIZE=2][COLOR=#2b91af][SIZE=2][COLOR=#2b91af]Exception[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] ex)[/SIZE]
[SIZE=2] {[/SIZE]
[SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff] throw [/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]new [/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#2b91af][SIZE=2][COLOR=#2b91af]Exception[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2](ex.ToString());[/SIZE]
[SIZE=2] }[/SIZE]
[SIZE=2]}[/SIZE]
[SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]public [/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]void[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] Methode([/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]string[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] Nom, [/SIZE][SIZE=2][COLOR=#2b91af][SIZE=2][COLOR=#2b91af]String[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][] Paramettres)[/SIZE]
[SIZE=2]{[/SIZE]
[SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff] object[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][] arg = [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]new [/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#2b91af][SIZE=2][COLOR=#2b91af]Object[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][Paramettres.Length];[/SIZE]
[SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff] for[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] ([/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]int[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] i = 0; i < Paramettres.Length; i++)[/SIZE]
[SIZE=2] {[/SIZE]
[SIZE=2] arg.SetValue(Paramettres[i], i);[/SIZE]
[SIZE=2] }[/SIZE]
[SIZE=2] objet.GetType().GetMethod(Nom).Invoke(objet, arg);[/SIZE]
[SIZE=2]}[/SIZE]
ParameterInfo[] pinfos = mi.GetParameters();
object[] args = new object[pinfos.Length];
if (pinfos.Length != 0)
{
for (int i = 0; i < numparams; i++)
{
Type t = pinfos[i].ParameterType;
args[i] = Convert.ChangeType(param[i], t, cul);
}
ret = mi.Invoke(obj, args);
}
else
{
ret = mi.Invoke(obj, null);
}
[SIZE=2][COLOR=#2b91af][SIZE=2][COLOR=#2b91af]MethodInfo[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] mi = objet.GetType().GetMethod(Nom);
[/SIZE][SIZE=2][COLOR=#2b91af][SIZE=2][COLOR=#2b91af]CultureInfo[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] cul = [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]new[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#2b91af][SIZE=2][COLOR=#2b91af]CultureInfo[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2](Nom);[/SIZE]
[SIZE=2]
mi looks OK but cul is wrong
Try
CultureInfo cul = new CultureInfo("en-US");
[SIZE=2][COLOR=#2b91af][SIZE=2][COLOR=#2b91af]Assembly[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] a = [/SIZE][SIZE=2][COLOR=#2b91af][SIZE=2][COLOR=#2b91af]Assembly[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2].LoadFrom(Fichier);[/SIZE]
[SIZE=2]objet = a.CreateInstance(Class);[/SIZE]
[SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]string[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] retour = [/SIZE][SIZE=2][COLOR=#a31515][SIZE=2][COLOR=#a31515]""[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2];[/SIZE]
[SIZE=2][COLOR=#2b91af][SIZE=2][COLOR=#2b91af]MethodInfo[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] mi=objet.GetType().GetMethod(Nom);[/SIZE]
[SIZE=2][COLOR=#2b91af][SIZE=2][COLOR=#2b91af]CultureInfo[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] cul = [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]new [/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#2b91af][SIZE=2][COLOR=#2b91af]CultureInfo[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]([/SIZE][SIZE=2][COLOR=#a31515][SIZE=2][COLOR=#a31515]"en-US"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]);[/SIZE]
[SIZE=2][COLOR=#2b91af][SIZE=2][COLOR=#2b91af]ParameterInfo[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][] pinfos = mi.GetParameters();[/SIZE]
[SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]object[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][] args = [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]new [/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]object[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][pinfos.Length];[/SIZE]
[SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]int[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] numparams = Paramettres.Length;[/SIZE]
[SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] (pinfos.Length != 0)[/SIZE]
[SIZE=2]{[/SIZE]
[SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff] for[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] ([/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]int[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] i = 0; i < numparams; i++)[/SIZE]
[SIZE=2] {[/SIZE]
[SIZE=2][COLOR=#2b91af][SIZE=2][COLOR=#2b91af] Type[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] t = pinfos[i].ParameterType;[/SIZE]
[SIZE=2] args[i] = [/SIZE][SIZE=2][COLOR=#2b91af][SIZE=2][COLOR=#2b91af]Convert[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2].ChangeType(Paramettres[i], t, cul);[/SIZE]
[SIZE=2] }[/SIZE]
[SIZE=2] retour = mi.Invoke(objet, args).ToString();[/SIZE]
[SIZE=2]}[/SIZE]
[SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]else[/COLOR][/SIZE]
[/COLOR][/SIZE][SIZE=2]{[/SIZE]
[SIZE=2] retour = mi.Invoke(objet, [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]null[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]).ToString();[/SIZE]
[SIZE=2]}[/SIZE]
[SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]return[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] retour;[/SIZE]
I don't know, which line does it error? A tip. Between each line when you get an object do something likeWhere is the problem?
[SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] (pinfos.Length != 0)[/SIZE]
[SIZE=2]{[/SIZE]
[SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]for[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] ([/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]int[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] i = 0; i < numparams; i++)[/SIZE]
[SIZE=2]{[/SIZE]
[SIZE=2][COLOR=#2b91af][SIZE=2][COLOR=#2b91af]Type[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] t = pinfos[i].ParameterType;[/SIZE]
[SIZE=2]args[i] = [/SIZE][SIZE=2][COLOR=#2b91af][SIZE=2][COLOR=#2b91af]Convert[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2].ChangeType(Paramettres[i], t, cul);[/SIZE]
[SIZE=2]}[/SIZE]
[SIZE=2]retour = mi.Invoke(objet, args).ToString();[/SIZE]
[SIZE=2]}[/SIZE]
[SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]else[/COLOR][/SIZE]
[/COLOR][/SIZE][SIZE=2]{[/SIZE]
[SIZE=2]retour = mi.Invoke(objet, [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]null[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]).ToString();[/SIZE]
[SIZE=2]}[/SIZE]
[SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]return[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] retour;[/SIZE]
[SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]namespace[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] fichier[/SIZE]
[SIZE=2]{[/SIZE]
[SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff] public [/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]class [/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#2b91af][SIZE=2][COLOR=#2b91af]teste[/COLOR][/SIZE]
[/COLOR][/SIZE][SIZE=2] {[/SIZE]
[SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff] public [/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]void[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] alerte([/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]string[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] txt)[/SIZE]
[SIZE=2] {[/SIZE]
[SIZE=2][COLOR=#2b91af][SIZE=2][COLOR=#2b91af] MessageBox[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2].Show(txt);[/SIZE]
[SIZE=2] }[/SIZE]
[SIZE=2] }[/SIZE]
[SIZE=2]}[/SIZE]
[SIZE=2][FONT=Courier New][SIZE=2][COLOR=#008b8b][FONT=Courier New][SIZE=2][COLOR=#008b8b][FONT=Courier New][SIZE=2][COLOR=#008b8b][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]tmp()=[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]Array[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]([/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000]"ok"[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2])[/SIZE][/FONT]
[/SIZE][/FONT]Dll[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2].New1[/SIZE][/FONT]
[/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#008b8b][FONT=Courier New][SIZE=2][COLOR=#008b8b][FONT=Courier New][SIZE=2][COLOR=#008b8b]Dll[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2].Importer([/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]AppPath[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]&[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000]"\fichier.dll"[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2],[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000]"fichier.teste"[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2])[/SIZE][/FONT]
[/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]Msgbox[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]([/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#008b8b][FONT=Courier New][SIZE=2][COLOR=#008b8b][FONT=Courier New][SIZE=2][COLOR=#008b8b]Dll[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2].Methode([/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000]"alerte"[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2],tmp()))[/SIZE][/FONT][/SIZE][/FONT]
[/SIZE]
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?