Tim Barrass
Tim Barrass

Reputation: 4939

TargetParameterCountException when creating an event in Facebook using the C# API

I'm using the C# SDK to post an event. I've filled out basic event parameters, and have tested these parameters with the Graph API explorer. When I call PostTaskAsync, however:

var parameters = new Dictionary<string, string>
    {
        { "name", "Random" },
        { "start_time", "2012-11-11" },
    };

fb.PostTaskAsync("me/events", parameters);

I'm hit with a TargetParameterCountException. Can anyone explain what I'm doing wrong?

Upvotes: 1

Views: 216

Answers (1)

John Grant
John Grant

Reputation: 563

The Facebook c# sdk expects the type implementing interface

IDictionary<string, object> 

See the FacebookClient.cs file in sdk version 6.4.2. Inside the ToDictionary() method there is a cast:

var dictionary = parameters as IDictionary<string, object>;

This cast produces null and the sdk cannot convert your dictionary type to the dictionary type expected.

Change the code to new up your dictionary to the correct type and your code ought to work!

Upvotes: 5

Related Questions