10

I'm using Facebook SDK C# Library in Asp.Net 3.5 Application. When I'm trying to compile the code below give me the errors. As I know dynamic type using in 4.0 framework. So is anyway to rewrite it in order make it work? I have a reference to System.Core 3.5 but it's still not compiling

protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.Params.AllKeys.Contains("signed_request"))
            {
                var result = FacebookSignedRequest.Parse(FacebookContext.Current.AppSecret, Request.Params["signed_request"]);
                dynamic signedRequestValue = result.Data;
                this.RegistrationData = signedRequestValue.registration;
            }
            else
            {
                Response.Redirect("~/");
            }
        }

protected dynamic RegistrationData { get; set; }


Error   1   Cannot define a class or member that utilizes 'dynamic' because the compiler required type 'System.Runtime.CompilerServices.DynamicAttribute' cannot be found. Are you missing a reference to System.Core.dll?  

Error   2   Cannot define a class or member that utilizes 'dynamic' because the compiler required type 'System.Runtime.CompilerServices.DynamicAttribute' cannot be found. Are you missing a reference to System.Core.dll?  
Anton
  • 101
  • 1
  • 1
  • 3

3 Answers3

7

My project was already > 4.0. It was 4.5.2, in fact. I was experiencing this error. What I did to fix it:

  1. I changed the project to 4.5.1.

  2. I changed it back to 4.5.2.

  3. Problem solved!

Thanks - hope this helps someone out there.

PS - not using facebook SDK, but this could help.

cr1pto
  • 539
  • 3
  • 13
7

dynamic is available in C# 4.0.

You have to convert your application to 4.0 version Change the referenced assemblies(System.Core) to 4.0 version.

Chandu
  • 81,493
  • 19
  • 133
  • 134
  • I cannot convert my application at this point to 4.0. Is there any way to adjust code? – Anton Mar 04 '11 at 06:08
  • Do you know data type of value returned by result.Data? – Chandu Mar 04 '11 at 06:14
  • Its returning Facebook.Json.Object which contains Keys and Values. value is string – Anton Mar 04 '11 at 06:24
  • @Anton What was the solution!?!?!?!? – mcandre Jan 28 '13 at 16:59
  • 1
    I'm having a similar problem (.net compiler is generating dynamic types and returning this error you mentioned). The thing is that all my System.Core references are version 4.0 (runtime version v4.0.30319) Any idea how could I resolve it? – Alejandro Lozdziejski Aug 01 '15 at 11:46
  • @AlejandroLozdziejski I have the same issue and my System.Core is version 4 already. Any idea what to do ? – Jay Jun 12 '16 at 15:38
0

If you don't want to use dynamic, you don't have to.

var client = new FacebookClient();
var me = client.Get("totten") as IDictionary<string, object>;
string firstName = (string)me["first_name"];
string lastName = me["last_name"].ToString();

This tutorial explains it more in depth

Mickey Perlstein
  • 2,508
  • 2
  • 30
  • 37