开发者

facebook c# 5 - FacebookWebClient throws Typeinitializer-exception

开发者 https://www.devze.com 2023-03-20 01:38 出处:网络
my problem is as follows: I have just migrated from using the Facebook C# API 4 -> v. 5.0.50 (as of 2011-07-11), therefore I had to change some lines of code and started using the FacebookWebClient in

my problem is as follows: I have just migrated from using the Facebook C# API 4 -> v. 5.0.50 (as of 2011-07-11), therefore I had to change some lines of code and started using the FacebookWebClient instead of the former FacebookApp. I use this class to navigate the Graph API. I use the functionality inside a WCF service, which receives only the access_token as a parameter, which it passes to the FacebookWebClient.

Everything worked just fine under v.4, however after replacing and re-referencing the dlls the application started throwing the exception "The type initializer for 'Facebook.FacebookApplication' threw an exception."


The exception stack trace is:

at Facebook.FacebookClient..ctor(String accessToken) in e:\Prabir\Documents\Projects\facebooksdk\v5.0.50\Source\Facebook\FacebookClient.cs:line 48 at Facebook.Web.FacebookWebClient..ctor(String accessToken) in e:\Prabir\Documents\Projects\facebooksdk\v5.0.50\Source\Facebook.Web\FacebookWebClient.cs:line 36 at Korito.MyKorito.FetchKorito(String token) at Korito.MyKorito.KoritoAPI(String token) at SyncInvokeKoritoAPI(Object , Object[] , Object[] ) at System.ServiceModel.Dispatcher.SyncMethodInvoker.Invoke(Object instance, Object[开发者_如何转开发] inputs, Object[]& outputs) at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage31(MessageRpc& rpc) at System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean isOperationContextSet)


I have referenced (only) the following dll-s:

  • facebook.dll
  • facebook.web.dll
  • facebook.web.mvc.dll

the code segment is as follows:

var client = new Facebook.Web.FacebookWebClient("/*auth_token_received_as_a_parameter*/"); dynamic me = client.Get("/me");

I use the .net 4 framework.

Any assistance is much appreciated! Cheers, Alois


FacebookWebClient is usually used when you want the SDK to automatically add the access token using the signed request or cookies.

var fb = new FacebookWebClient();

Since you are getting the access token as parameter. You could just reference Facebook.dll only and use FacebookClient instead.

var client = new FacebookClient("access_token");

You can continue to use FacebookApp which has been moved to Facebook.Web.dll in v5.x (You might not see it in intellisense as it is hidden but it still works as we tried to maintain as maximum compatibilty with v4. note: but it has been marked as obsolete, this allows users to easily migrate their apps from v4 to v5.)

0

精彩评论

暂无评论...
验证码 换一张
取 消