1

我有一個Windows應用程序,它可以訪問Google電子表格來創建電話簿。當我嘗試打開電話簿時,出現System.NotImplementedException: The method or operation is not implemented.我不太確定爲什麼,因爲它似乎正在實施?訪問ServiceAccountCredential時發生NotImplementedException C#

這就是會被這個問題標記的第一點:

internal object FromCertificate(X509Certificate2 certificate) 
     { 
      throw new NotImplementedException(); //Error flags this line 
     } 

這是第二次。據我所知,這部分沒有任何問題,但它仍然會標記異常。

ServiceAccountCredential credential = new ServiceAccountCredential(
      new ServiceAccountCredential.Initializer(serviceAccountEmail) 
      { 
       Scopes = new[] { "https://www.googleapis.com/auth/spreadsheets", "https://docs.google.com/feeds" } 
      }.FromCertificate(certificate)); 

任何建議將非常感激。我在C#中使用Visual Studio 2015.

回答

1

我不太確定爲什麼,因爲它似乎正在實施?

的贈品是這條線的位置:

throw new NotImplementedException(); 

throw new NotImplementedException()通常刪空當從Visual Studio樣板方法。

它沒有被執行,只是因爲你從對象.FromCertificate(certificate)中調用它。這只是調用方法,然後運行其中的代碼。人機工程學,它就會打你的throw new NotImplementedException();代碼 - 從而打破等

實現你的方法,你需要刪除throw new NotImplementedException();,並用自己的邏輯取代它。

您將需要添加一些代碼在你FromCertificate()方法:

internal object FromCertificate(X509Certificate2 certificate) 
{ 
    // Do some work in here 
} 

希望這有助於:)

+1

我想補充爲什麼你的「第二點」的頹勢了一個例外:你'NotImplementedException'從你的方法冒泡回來,調試器從它被調用的地方通知你,當它返回到那裏。如果你處理(catch)它降低,它不會回升,除非你重新拋出(再次拋出) –

相關問題