The type initializer for 'Facebook.FacebookApplication' threw an exception
I am using Facebook APIs w/ oAuth using their Javascript SDK to sign in, and setting oAuth = true. I can from the SDK sign in successfully, and get my xfbml to render properly.
I am using the Facebook C# sdk to retrieve the user ID and post to FB. I wrote a small test page that does this.
HTML is:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="fbtest.aspx.cs" Inherits="fbtest" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
ID:<asp:label runat="server" text="Label" ID="Userid"></asp:label><div />
<asp:label runat="server" text="Label" ID="FacebookTokenLabel"></asp:label>
</div>
</form>
</body>
</html>
The Code behind is:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Facebook;
using Facebook.Web;
public partial class fbtest : System.Web.UI.Page
{
private FacebookWebClient _facebookApp;
protected void Page_Load(object sender, EventArgs e)
{
try
{
// FacebookWebContext fbWebContext = FacebookWebContext.Current;
// FacebookTokenLabel.Text += fbWebContext.AccessToken;
FacebookWebClient fb = new FacebookWebClient();
dynamic me = fb.Get("me");
FacebookTokenLabel.Text = me.name;
Userid.Text = me.id;
}
catch (Exception ex)
{
FacebookTokenLabel.Text = ex.Message + ":" + ex.StackTrace;
}
}
}
I tried on all browsers (IE9, chrome 14.0.835.186 m and FF 6.0.2) and i get the same exception:
ID:Label
The type initializer for 'Facebook.FacebookApplication' threw an exception.:
at Facebook.FacebookApplication.get_Current() in e:\Prabir\Documents\Projects\facebooksdk\v5.2.1\Source\Facebook\FacebookApplication.cs:line 48
at Facebook.Web.FacebookWebContext..ctor() in e:\Prabir\Documents\Projects\facebooksdk\v5.2.1\Source\Facebook.Web\FacebookWebContext.cs:line 48
at Facebook.Web.FacebookWebContex开发者_开发问答t.get_Current() in e:\Prabir\Documents\Projects\facebooksdk\v5.2.1\Source\Facebook.Web\FacebookWebContext.cs:line 96
at fbtest.Page_Load(Object sender, EventArgs e) in c:\inetpub\vhosts\beirutna.com\subdomains\beta\httpdocs\fbtest.aspx.cs:line 16
You can try yourself: http://beta.beirutna.com and log in on the top right, it will show your user name and tile. Then go to: http://http://beta.beirutna.com/fbtest.aspx
Check your inner exception
In my case it revealed: Request for ConfigurationPermission failed while attempting to access configuration section 'facebookSettings'. To allow all callers to access the data for this section, set section attribute 'requirePermission' equal 'false' in the configuration file where this section is declared.
精彩评论