ravipatidar54 / google-api-dotnet-client

Automatically exported from code.google.com/p/google-api-dotnet-client
Apache License 2.0
0 stars 0 forks source link

System.TypeInitializationException was unhandled #244

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Create new Project in VS2010
2. Download .net samples
3. Add references 
4. Paste code from https://developers.google.com/drive/quickstart
5. Run Code

What is the expected output? What do you see instead?
when running 
var service = new DriveService(auth);
I am prompted for location of services.cs
From the prompt, the file is expected to be found in 
c:\google\google-api-dotnet-client\7-9-2012\default\Src\GoogleApis\Apis\Discover
y\Service.cs

What version of the product are you using? On what operating system?
20120709-1.2.4573-beta, Windows 7 64-bit

Please provide any additional information below.

Code
using System;
using System.Diagnostics;
using DotNetOpenAuth.OAuth2;
using Google.Apis.Authentication.OAuth2;
using Google.Apis.Authentication.OAuth2.DotNetOpenAuth;
using Google.Apis.Drive.v2;
using Google.Apis.Drive.v2.Data;
using Google.Apis.Util;

namespace UploadToGoogleDrive
{
    class DriveCommandLineSample
    {
        static void Main(string[] args)
        {
            String CLIENT_ID = "YOUR_CLIENT_ID";//removed my CLIENT_ID
            String CLIENT_SECRET = "YOUR_CLIENT_SECRET";//removed my SECRET_KEY

            // Register the authenticator and create the service
            var provider = new NativeApplicationClient(GoogleAuthenticationServer.Description, CLIENT_ID, CLIENT_SECRET);
            var auth = new OAuth2Authenticator<NativeApplicationClient>(provider, GetAuthorization);

// Line that causes error
var service = new DriveService(auth);

            File body = new File();
            body.Title = "My document";
            body.Description = "A test document";
            body.MimeType = "text/plain";

            byte[] byteArray = System.IO.File.ReadAllBytes("document.txt");
            System.IO.MemoryStream stream = new System.IO.MemoryStream(byteArray);

            FilesResource.InsertMediaUpload request = service.Files.Insert(body, stream, "text/plain");
            request.Upload();

            File file = request.ResponseBody;
            Console.WriteLine("File id: " + file.Id);
        }

        private static IAuthorizationState GetAuthorization(NativeApplicationClient arg)
        {
            // Get the auth URL:
            IAuthorizationState state = new AuthorizationState(new[] { DriveService.Scopes.Drive.GetStringValue() });
            state.Callback = new Uri(NativeApplicationClient.OutOfBandCallbackUrl);
            Uri authUri = arg.RequestUserAuthorization(state);

            // Request authorization from the user (by opening a browser window):
            Process.Start(authUri.ToString());
            Console.Write("  Authorization Code: ");
            string authCode = Console.ReadLine();
            Console.WriteLine();

            // Retrieve the access token by using the authorization code:
            return arg.ProcessUserAuthorization(authCode, state);
        }
    }
}

Original issue reported on code.google.com by nycomput...@gmail.com on 25 Aug 2012 at 4:50

GoogleCodeExporter commented 9 years ago
Hi, 
I assume this is when you are debugging? If so this is only required to step 
into the library code which most people do not require, so you can just step 
over or out or just cancel the dialog.

If you are wanting to step in to the code for any reason you can download the 
source either from the source control system 
(http://code.google.com/p/google-api-dotnet-client/source/checkout) or from the 
source zip next to the version of the library you downloaded. 

Original comment by davidwat...@google.com on 28 Aug 2012 at 7:27