Search code examples
c#youtubegdata

Null Reference Exception on YoutubeRequest Instantiation


I am running a c# web app that includes the ability to upload video to youtube. I am using the gdata library for .NET. However, when I hit this line in my upload video code (in the function that generates my authenticated request)

YouTubeRequest req = new YouTubeRequest(sett);

I get an Null Reference Exception, the full function that creates my request is as follows:

public YouTubeRequest getReq()
{
        YouTubeRequestSettings sett = new YouTubeRequestSettings("Video-Postcard", devKey, consumerKey, consumerSecret, token, tokenSecret, "default", "video-postcard.com");
        YouTubeRequest req = new YouTubeRequest(sett);
        AsymmetricAlgorithm pk = getRsaKey();
        GAuthSubRequestFactory facto = new GAuthSubRequestFactory("youtube", "Video-Postcard");
        facto.PrivateKey = pk;
        facto.Token = token;
        req.Service.RequestFactory = (IGDataRequestFactory)facto;
        ((GDataRequestFactory)req.Service.RequestFactory).KeepAlive = false;
        ((GDataRequestFactory)req.Service.RequestFactory).Timeout = 360000;
        return req;
}

I use this same piece of code to generate the requests for a different part of my app that searches youtube, but when I am uploading a video, I get the exception. I have been messing with this for 2 days now with no changes, any ideas?


Solution

  • Are devKey, consumerKey, consumerSecret, token and tokenSecret all non-null when you instantiate the YouTubeRequestSettings object?