访问ServiceAccountCredential时发生NotImplementedException C#

问题描述:

我有一个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.

我不太确定为什么,因为它似乎正在实施?

的赠品是这条线的位置:

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)它降低,它不会回升,除非你重新抛出(再次抛出) –