vendredi 19 avril 2019

how to Invoke method when not knowing the class of the parameters, error GenericArguments

I was trying to use sharepoint without referencing to the dll in visual studio but use "Assembly.LoadFrom".

static Assembly sharepointClient = Assembly.LoadFrom(@"C:\Program Files\EPLAN\Platform\2.8.3\Bin\Microsoft.SharePoint.Client.dll"); 

I came to the point i need to invoke the "load" method of clientcontext with the webinfo

object clientContext = Activator.CreateInstance(typeclientContext, args);

So i got this to get the value of the property web and invoke it in the method load

PropertyInfo webPropertyInfo = typeclientContext.GetProperty("Web");
object web = (object)webPropertyInfo.GetValue(clientContext, null);
//Load clientcontext
//clientContext.Load(web);
MethodInfo methodInfoLoad = typeclientContext.GetMethod("Load");
object[] args3 = { web };
methodInfoLoad = methodInfoLoad.MakeGenericMethod(typeclientContext);
methodInfoLoad.Invoke(clientContext, args3);

At this point it tells me that args has to be generic but i can't make it generic cause i don't have the class from in the dll of sharepoint. Or am i missing something? How can i make it generic?

Here is the error:

error: GenericArguments[0], 'Microsoft.SharePoint.Client.ClientContext', on 'Void Load[T](T, System.Linq.Expressions.Expression`1[System.Func`2[T,System.Object]][])' violates the constraint of type 'T'.





Aucun commentaire:

Enregistrer un commentaire