无法定义使用动态的类或成员,因为编译器需要类型
我在Asp.Net 3.5应用程序中使用Facebook SDK C#Library。 当我试图编译下面的代码给我错误。 据我所知在4.0框架中使用动态类型。 所以无论如何要重写它以使它工作? 我有一个System.Core 3.5的引用,但它仍然没有编译
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?
动态在C#4.0中可用。
您必须将应用程序转换为4.0版本将引用的程序集(System.Core)更改为4.0版本。
我的项目已经> 4.0。 事实上,它是4.5.2。 我遇到了这个错误。 我做了什么修复它:
-
我将项目更改为4.5.1。
-
我把它改回4.5.2。
-
问题解决了!
谢谢 – 希望这有助于那里的人。
PS – 不使用Facebook SDK,但这可能有所帮助。
如果您不想使用动态,则不必使用。
var client = new FacebookClient(); var me = client.Get("totten") as IDictionary; string firstName = (string)me["first_name"]; string lastName = me["last_name"].ToString();
本教程更深入地解释了它