VB.NET lambda expressions ... what am I doing wrong?

when I run this code in C #, no problem ... but when I translate it into VB.NET, it compiles, but it hits because the "CompareString" member is not allowed in the expression ... I feel like I'm missing something here ...

private void PrintButton_Click(object sender, EventArgs e)
{
if (ListsListBox.SelectedIndex > -1)
{
    //Context
    using (ClientOM.ClientContext ctx =
        new ClientOM.ClientContext(UrlTextBox.Text))
    {
        //Get selected list
        string listTitle = ListsListBox.SelectedItem.ToString();
        ClientOM.Web site = ctx.Web;
        ctx.Load(site,
            s => s.Lists.Where(l => l.Title == listTitle));
        ctx.ExecuteQuery();

        ClientOM.List list = site.Lists[0];

        //Get fields for this list
        ctx.Load(list,
            l => l.Fields.Where(f => f.Hidden == false 
      && (f.CanBeDeleted == true || f.InternalName == "Title")));
        ctx.ExecuteQuery();

        //Get items for the list
     ClientOM.ListItemCollection listItems = list.GetItems(
      ClientOM.CamlQuery.CreateAllItemsQuery());
        ctx.Load(listItems);
        ctx.ExecuteQuery();

        // DOCUMENT CREATION CODE GOES HERE

    }

    MessageBox.Show("Document Created!");
}

}

but in VB.NET code these errors are due to the fact that CompareString members are not allowed in the ctx.Load () methods ...

Private Sub PrintButton_Click(sender As Object, e As EventArgs)
    If ListsListBox.SelectedIndex > -1 Then
        'Context
        Using ctx As New ClientOM.ClientContext(UrlTextBox.Text)
            'Get selected list
            Dim listTitle As String = ListsListBox.SelectedItem.ToString()
            Dim site As ClientOM.Web = ctx.Web
            ctx.Load(site, Function(s) s.Lists.Where(Function(l) l.Title = listTitle))
            ctx.ExecuteQuery()

            Dim list As ClientOM.List = site.Lists(0)

            'Get fields for this list
            ctx.Load(list, Function(l) l.Fields.Where(Function(f) f.Hidden = False AndAlso (f.CanBeDeleted = True OrElse f.InternalName = "Title")))
            ctx.ExecuteQuery()

            'Get items for the list
            Dim listItems As ClientOM.ListItemCollection = list.GetItems(ClientOM.CamlQuery.CreateAllItemsQuery())
            ctx.Load(listItems)

            ' DOCUMENT CREATION CODE GOES HERE

            ctx.ExecuteQuery()
        End Using

        MessageBox.Show("Document Created!")
    End If
End Sub
+3
source share
2 answers

This is probably because VB uses its own implementation of the comparison operator, rather than an implementation in a string class, so the expression cannot be used by the Load method.

Try using the Equals method:

ctx.Load(site, Function(s) s.Lists.Where(Function(l) l.Title.Equals(listTitle)))

, LINQ eq, , VB .

+2

: Microsoft.SharePoint.Client.ClientRequestException: "CompareString" .

LINQ VB.NET, SharePoint, .

KB 2883454:

, VB.NET :

s = "abc"

:

0 == Microsoft.VisualBasic.CompilerServices.Operators.CompareString(s, "abc", true)

SharePoint.

, #.NET VB.NET .

+1
source

Source: https://habr.com/ru/post/1736213/


All Articles