Quantcast
Channel: SharePoint 2013 - Development and Programming forum
Viewing all articles
Browse latest Browse all 7589

Client Object Model - 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'

$
0
0

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=()


Viewing all articles
Browse latest Browse all 7589


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>