2013-09-28 29 views
5

我需要一個小的幫助 我創建了一個小physioit應用Windows Phone的8Facebook的loginbutton SDK在C#應用程序崩潰

我在XAML文件添加facebookclient loginbutton。 現在,當我的手機中沒有數據連接並且運行代碼時,它會給我TargetInvocationException和我的應用程序崩潰。

這是我得到的例外 -

innerException 
{Facebook.WebExceptionWrapper: The remote server returned an error: NotFound. ---> 
     System.Net.WebException: The remote server returned an error: NotFound. 
at System.Net.Browser.ClientHttpWebRequest.InternalEndGetResponse(IAsyncResult asyncResult) 
at System.Net.Browser.ClientHttpWebRequest.<>c__DisplayClasse.<EndGetResponse>b__d(Object sendState) 
at System.Net.Browser.AsyncHelper.<>c__DisplayClass1.<BeginOnUI>b__0(Object sendState) 
--- End of inner exception stack trace ---}   

System.Exception  {Facebook.WebExceptionWrapper} 

我怎麼能捕獲此異常?

我使用Facebook SDK創建loginbutton

這裏是代碼片段

<facebookControls:LoginButton 
    x:Name="loginButton" 
    Grid.Row="2" 
    Margin="5" 
    HorizontalAlignment="Right" 
    FetchUserInfo="True"  
    ApplicationId="xxxxxx" 
    SessionStateChanged="OnFacebookSessionStateChanged" 
    UserInfoChanged="OnFacebookUserInfoChanged" 
    AuthenticationError="LoginButtonAuthenticationError" /> 

你能幫幫我。

+0

尼斯捕撈,這是不可思議。我猜想它不應該通過設計讓應用崩潰。你有沒有在https://github.com/facebook-csharp-sdk/facebook-csharp-sdk/issues上報告這個問題? 兩種可能的解決方法是 1)不使用的登錄按鈕進行登錄 2)不重視的applicationID,直到你確信有互聯網連接(技巧) –

+1

只是一個猜測 - 確保您已啓用所有功能facebook sdk需要在您的wmappmanifest.xml文件中 –

回答

0

您可以使用NetworkInterface檢查數據連接是否可用,然後允許登錄按鈕執行其操作。

事情是這樣的..

if(System.Net.NetworkInformation.NetworkInterface.GetIsNetworkAvailable()) 
//Allow login button 
else 
//Message user - no internet connection