【问题标题】:NotImplementedException when Accessing ServiceAccountCredential C#访问 ServiceAccountCredential C# 时出现 NotImplementedException
【发布时间】:2016-06-20 17:27:40
【问题描述】:

我有一个 Windows 应用程序可以访问 Google 电子表格来创建电话簿。当我尝试打开电话簿时,我被标记为System.NotImplementedException: The method or operation is not implemented. 我不太确定为什么,因为它似乎正在实施?

这是第一个被标记的问题:

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));

任何建议将不胜感激。我在 Visual Studio 2015 中使用 C#。

【问题讨论】:

    标签: c# visual-studio-2015 google-spreadsheet-api x509certificate2 notimplementedexception


    【解决方案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
    }
    

    希望这会有所帮助:)

    【讨论】:

    • 只是补充一下为什么你的“第二点”标记了一个异常:你的方法中的NotImplementedException 正在冒泡,并且调试器从它被调用的地方通知你,当它返回那里时。如果您将 (catch) 向下处理,除非您重新抛出 (throw 再次),否则它不会再起泡
    猜你喜欢
    • 2021-09-18
    • 2021-06-30
    • 2022-01-07
    • 2016-03-23
    • 2011-06-08
    • 2011-10-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多