首页 文章

facebook c#5 - FacebookWebClient抛出Typeinitializer异常

提问于
浏览
0

我的问题如下:我刚从使用Facebook C#API 4 - > v.5.0.50(截至2011-07-11)迁移,因此我不得不更改一些代码行并开始使用FacebookWebClient而不是前FacebookApp . 我使用这个类来导航Graph API . 我使用WCF服务中的功能,该服务仅接收access_token作为参数,并将其传递给FacebookWebClient .

在v.4下一切正常,但是在替换和重新引用dll后,应用程序开始抛出异常“ The type initializer for 'Facebook.FacebookApplication' threw an exception.


异常堆栈跟踪是:

在Facebook.FacebookClient..ctor(String accessToken)的e:\ Prabir \ Documents \ Projects \ facebooksdk \ v5.0.50 \ Source \ Facebook \ FacebookClient.cs:第48行在Facebook.Web.FacebookWebClient..ctor(String accessToken)在e:\ Prabir \ Documents \ Projects \ facebooksdk \ v5.0.50 \ Source \ Facebook.Web \ FacebookWebClient.cs:第36行,位于Korito.MyKorito.FetchKorito(String token),位于SyncInvokeKoritoAPI的Korito.MyKorito.KoritoAPI(String token) System.ServiceModel.Dispatcher上的System.ServiceModel.Dispatcher.SyncMethodInvoker.Invoke(Object实例,Object []输入,Object []和输出)中的(Object,Object [],Object [])(MessageRpc&rpc)在在System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage31 System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc&RPC)在System.ServiceModel.Dispatcher.MessageRpc.Process(MessageRpc&RPC)(布尔isOperationContextSet)


我引用了(仅)以下的dll-s:

  • facebook.dll

  • facebook.web.dll

  • facebook.web.mvc.dll

代码段如下:

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

我使用.net 4框架 .

非常感谢任何帮助!干杯,阿洛伊斯

1 回答

  • 0

    当您希望SDK使用签名的请求或cookie自动添加访问令牌时,通常会使用FacebookWebClient .

    var fb = new FacebookWebClient();
    

    因为您将获取访问令牌作为参数 . 您只能引用Facebook.dll并使用FacebookClient .

    var client = new FacebookClient("access_token");
    

    您可以继续使用已转移到v5.x中的Facebook.Web.dll的FacebookApp(您可能无法在intellisense中看到它,因为它被隐藏但它仍然有效,因为我们试图保持与v4的最大兼容性 . 注意:但是它已被标记为已过时,这使用户可以轻松地将其应用程序从v4迁移到v5 . )

相关问题