What is wrong with this code... seems harmless to me.
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Microsoft.SharePoint; using Microsoft.SharePoint.Client; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { ClientContext c = new ClientContext("http://sp2013.mycompany.com/sites/dev"); Web web = c.Web; c.Load(web, w => w.Title, w => w.Fields); c.ExecuteQuery(); Console.WriteLine(web.Title); FieldCollection collField = web.Fields; c.Load(collField, fields => fields.Include(field => field.Title)); c.ExecuteQuery(); foreach (Field x in collField) { Console.WriteLine(x.Title); } } } }
Unhandled Exception: System.InvalidCastException: Unable to cast object of type'System.Collections.Generic.Dictionary`2[Syst
em.String,System.Object]' to type 'Microsoft.SharePoint.Client.Field'.
at Microsoft.SharePoint.Client.ClientObjectCollection`1.<System.Collections.Generic.IEnumerable<T>.GetEnumerator>d__0.Move
Next()
at ConsoleApplication1.Program.Main(String[] args) in c:\temp\ConsoleApplication1\ConsoleApplication1\Program.cs:line 20
Press any key to continue . . .
val it: unit=()