I try to use Dynamic DLL (Hangfire Core). Some methods of this lib has non-standard arguments, for example
public static IGlobalConfiguration UseSimpleAssemblyNameTypeSerializer([NotNull] this IGlobalConfiguration configuration)
If i want call method with reflection help, I did:
- Load Assembly
- Get type from assembly
- Get method from type
- Try Invoke method
and, I got error:
Object of type 'System.RuntimeType' cannot be converted to type 'Hangfire.IGlobalConfiguration'."
My code:
private static void GetField(string typeName, string pathToDll, string fieldName)
{
Type GlobalConfigurationType = Assembly.LoadFile(@pathToDll).GetType(typeName);
Type GlobalConfigurationExtensionType = Assembly.LoadFile(@pathToDll).GetType("Hangfire.GlobalConfigurationExtensions");
var propertyInfos = GlobalConfigurationType.GetProperties();
var someProperty = propertyInfos[0];
var UseSimpleAssemblyNameTypeSerializerMethod = GlobalConfigurationExtensionType.GetMethod("UseSimpleAssemblyNameTypeSerializer");
UseSimpleAssemblyNameTypeSerializerMethod?.Invoke(null, new object[] { someProperty.PropertyType });
}
How to do the conversion correctly?
I tried to set .PropertyType as argument
Aucun commentaire:
Enregistrer un commentaire