tags:

views:

179

answers:

2

when I run this C# code, no problems... but when I translate it into VB.NET it compiles but blows due to 'CompareString' member not being allowed in the expression... I feel like I'm missing something key 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 this errors due to not being allowed 'CompareString' members 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
+2  A: 

That is probably because VB is using it's own implementation of the comparison operator, not the implementation in the string class, so the expression can't 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)))

If that doesn't work, there is an eq operator in LINQ that works in expressions, but I would have to look up the VB syntax for that.

Guffa
Tried the .Equals and I get a runtime error that this is not supported...
Bob
in fact all string operations on this do not seem to be supported which is odd considering that both items in the comparison are strings...
Bob
A: 

I ran into this issue when trying to string comparison using SubSonic. I do not know if you have seen this question or not. You can view this issue here...

http://stackoverflow.com/questions/1145829/vb-net-cant-find-by-string

Lance