Issue Calling .NET inherited class (method not found)

Posted by bharold on 12-Dec-2017 10:04


I am trying to convert following c# code to Openedge.


C# code:
------------
using Microsoft.SharePoint.Client.Runtime;
using Microsoft.SharePoint.Client;
using System;

namespace sharepoint_Demo
{
    class Program
    {
        static void Main(string[] args)
        {
            ClientContext clientContext = new  ClientContext("http://mytestportal/");
            Web web = clientContext.Web;
            clientContext.Load(web);
            clientContext.ExecuteQuery();
            Console.WriteLine(web.Title);
        }
     }
}            


Converted OpenEdge Code:
---------------------------------------
using Microsoft.SharePoint.client.Runtime.*.
using Microsoft.SharePoint.Client.*.
using System.*.
DEFINE VARIABLE clientContextVar AS ClientContext.
DEFINE VARIABLE web1 AS Microsoft.SharePoint.Client.Web.

clientContextVar = new ClientContext("http://mytestportal").
Web1 = clientContextVar:Web.
clientContextVar:Load(web1).  /* <- Compile Error - could not locate element 'load' in the class Microsoft.Sharepoint.Client.ClientContext ( 12927) **/
clientcontextVar:ExecuteQuery().
display web1:Title.



I am trying to use Sharepoint .NET assembly in the openedge program. I have converted a simple C# example to Openedge. C# example works fine in Visual Studio.
But my OpenEdge code is not compiling:   code snippent is giving me an error that could not locate element 'load' in the class Microsoft.Sharepoint.Client.ClientContext ( 12927).

I see the Load method in Visual Studio for the ClientContext class. But When I view the same assembly in Class browser then I do not see Load method under Microsoft.SharePoint namespace anywhere.

Here is the microsoft documentation for the load method: 

msdn.microsoft.com/.../microsoft.sharepoint.client.clientcontext_methods.aspx

What am I missing?  I am using OpenEdge 11.7.

- Brady


Posted by Laura Stern on 12-Dec-2017 10:50

That is because the method is not Load.  It is Load<T>.  This is a generic method.  You cannot call generic methods right now from the ABL.  

All Replies

Posted by Laura Stern on 12-Dec-2017 10:50

That is because the method is not Load.  It is Load<T>.  This is a generic method.  You cannot call generic methods right now from the ABL.  

Posted by Laura Stern on 12-Dec-2017 10:51

That is because there is no method Load.  It is Load<T>.  That is a generic method.  You cannot call generic methods right now from the ABL.

Posted by Mike Fechner on 12-Dec-2017 14:22

You can - using .NET Reflection:

github.com/.../ReflectionHelperOSS

Consultingwerk.Util.ReflectionHelper:InvokeGenericMethod (objectRef, "methodName", <T> as a System.Type).

Posted by Laura Stern on 12-Dec-2017 14:30

Oh, you're so clever Mike!

Posted by bharold41 on 13-Dec-2017 09:57

Mike and Laura,

Thank You. This is very helpful.  I am still beginner with .NET .  I have downloaded ReflectionHelper files.  Can you please help me with the syntax?  I am getting runtime error with my attempt to use ReflectionHelper class.

Runtime error:  System.Argument.Exception: GenericArguments[0].  Microsoft.SharePoint.Client.ClientRuntimeContext on Void Load[t]. System.Linq.Expressions.Expression violates the constraint of type T

C# syntax:

    Web web1 = clientContext.Web;

   clientContext.Load(web1);

OpenEdge Program:

USING Microsoft.SharePoint.Client.ClientContext.

USING Microsoft.SharePoint.Client.Runtime.*.

USING Microsoft.SharePoint.Client.*.

DEFINE VARIABLE clientContextVar as ClientContext.

DEFINE VARIABLE web1 AS Web.

DEFINE VARIABLE oClientRunTime AS ClientRuntimeContext NO-UNDO .

clientContextVar = new ClientContext("").

Web1 = clientContextVar:Web.

oClientRunTime = CAST (ReflectionHelper:InvokeGenericMethod (clientContextVar,

                                       "Load":U,

                                       "Microsoft.SharePoint.Client.ClientRuntimeContext":U),ClientRuntimeContext) .

/** oClientRunTime(web1). **/

message valid-object(oclientruntime) view-as alert-box.

clientcontextVar:ExecuteQuery().

display web1:Title.

Posted by Laura Stern on 13-Dec-2017 10:23

I probably shouldn't speak for Mike, but I think he was saying that the last parameter should be an instance of System.Type for the type <T>.  It is not just a string.  So you could call the static .NET method GetType():

DEFINE VAR TType as System.Type.

TType = System.Type:GetType( "Microsoft.SharePoint.Client.ClientRuntimeContext").

And then pass TType as the last parameter:

ReflectionHelper:InvokeGenericMethod (clientContextVar, "Load":U, TType).

Posted by bharold41 on 13-Dec-2017 12:51

I am very close. Thanks for helping me out.

tType is not  as  not valid object when I perform GET-TYPE on my class.

Also, 3rd parameter in the ReflectionHelper is Character. Should I use tType:Name  as a 3rd parameter?

DEFINE VAR TType as System.Type.

TType = System.Type:GetType( "Microsoft.SharePoint.Client.Runtime").

message  VALID-OBJECT(TType) view-as alert-box.  // <- Displays NO

Web1 = clientContextVar:Web.

ReflectionHelper:InvokeGenericMethod (clientContextVar,"Load":U,String(tType),web1,"web").

Posted by Laura Stern on 13-Dec-2017 13:01

Sorry - I'm just mimicking what you had in your example.  Correct - it looks like Microsoft.SharePoint.Client.Runtime is not a valid class type as I cannot find doc on it.  it is actually the name of an assembly, not the name of a class.  You need to be clear what types you are dealing with.  I cannot help you with that!

Regarding the 3rd parameter - seems you will need help from Mike.  I'm just interpreting what he said above, which was "<T> as a System.Type".  That doesn't sound like a character to me.  But I don't have his code, so I have no idea.  

Posted by Mike Fechner on 13-Dec-2017 13:23

> TType = System.Type:GetType( "Microsoft.SharePoint.Client.Runtime").

I'd suggest to use Progress.Util.TypeHelper:GetType ("typename") . instead.

But according to msdn.microsoft.com/.../microsoft.sharepoint.client.aspx there is no type called Microsoft.SharePoint.Client.Runtime

Posted by Laura Stern on 13-Dec-2017 13:33

Mike - why do you say that?  What's wrong with just calling GetType directly?  Not that using TypeHelper wouldn't work.

Also, I assume you didn't literally mean "typename".  You meant "<typename>", right?

The problem there was just that you have to use the name of a valid type.

But please verify whether I was correct - the 3rd parameter should be an instance of System.Type,  (or a character string?).

Posted by Mike Fechner on 13-Dec-2017 13:47

Hi Laura,

IMHO System.Type.GetType() only returns a System.Type reference when the type is in an assembly already loaded by the AVM session. Progress.Util.TypeHelper:GetType() is able to load assemblies (referenced in assemblies.xml) for first use.

I tried this here in a fresh prowin session (and yes, my assemblies.xml contains all the infragistics.assemblies):

DEFINE VARIABLE cType AS CHARACTER   NO-UNDO

   INITIAL "Infragistics.Win.Appearance".

MESSAGE System.Type:GetType (cType) SKIP

       Progress.Util.TypeHelper:GetType (cType)

   VIEW-AS ALERT-BOX INFORMATION BUTTONS OK.

And the message gives me

?

Infragistics.Win.Appearance

telling me, that the System.Type:GetType returns an invalid object reference while Progress.Util.TypeHelper returns a value reference. If it's not that, is Progress.Util.TypeHelper no longer needed in your POV? Im on 11.7.2.001 FWIW.

As for the arguments of the ReflectionHelper (help.consultingwerkcloud.com/.../Consultingwerk.Util.ReflectionHelper.html)

The third parameter is the type name (as a string, we use the Progress.Util.TypeHelper:GetType inside the method) to be used for <T> but referenced without the < and >, so "Microsoft.SharePoint.Client.ClientRuntimeContext"

With Brady's error:

"Runtime error:  System.Argument.Exception: GenericArguments[0].  Microsoft.SharePoint.Client.ClientRuntimeContext on Void Load[t]. System.Linq.Expressions.Expression violates the constraint of type T"

my assumption is, he's using a Type T which is illegal for Load<T> or just not valid.

Posted by Laura Stern on 13-Dec-2017 13:53

Oh yes!  You're correct about GetType.  I forgot!  THANKS for all of that.

Posted by marian.edu on 14-Dec-2017 01:38

It looks to me you’re passing a Web instance to the Load method so probably the type you’re looking for is Microsoft.SharePoint.Client.Web 


InvokeGenericMethod (clientContextVar, ”Load”:U, “Microsoft.SharePoint.Client.Web”, web1, ”Microsoft.SharePoint.Client.Web”)

Marian Edu

Acorn IT 
+40 740 036 212

Posted by bharold41 on 14-Dec-2017 07:29

I have tried following 2 syntax and I am getting an error:  

'System.InvalidCastException: Object can not be stored in array of this type'.      

ReflectionHelper:InvokeGenericMethod (clientContextVar,"Load":U,"Microsoft.SharePoint.Client.ClientRuntimeContext",web1,"Microsoft.SharePoint.Client.Web").

ReflectionHelper:InvokeGenericMethod (clientContextVar, "Load":U, "Microsoft.SharePoint.Client.Web", web1, "Microsoft.SharePoint.Client.Web").

This thread is closed