NotImplementedException when Accessing ServiceAccountCredential C#

北慕城南 提交于 2019-12-24 08:23:14

问题


I have a Windows app that access a Google spreadsheet to create a phone book. When I try to open the phone book, I get flagged with System.NotImplementedException: The method or operation is not implemented. I'm not really sure why, because it seems like it is being implemented?

This is the first spot that's being flagged with the issue:

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

This is the second. As far as I can tell, there's nothing wrong with this part but it's still flagging an exception.

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

Any suggestions would be really appreciated. I'm using C# with Visual Studio 2015.


回答1:


I'm not really sure why, becayse it seems like it is being implemented?

The giveaway is this line here:

throw new NotImplementedException();

The throw new NotImplementedException() is usually boiler-plate from Visual Studio when stubbing out methods.

It isn't being implemented, just because you're calling it from the object with .FromCertificate(certificate). This is just calling the method, which then runs the code within it. Ergo, it then hits your throw new NotImplementedException(); code - thus breaking etc.

To implement your method, you need to remove the throw new NotImplementedException(); and replace it with your own logic.

You will need to add some code in your FromCertificate() method:

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

Hope this helps :)



来源:https://stackoverflow.com/questions/37928423/notimplementedexception-when-accessing-serviceaccountcredential-c-sharp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!