0

I cannot figure this one out, on a release of a program that uploads a file to Google Drive through V3 of the API, an exception, as follows, is throw:

FileNotFoundException: Could not load file or assembly 'System.Net.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.

This does not happen in debug mode but in release mode and published versions. I have removed, then updated, then re added the system.Net.Http references to the project. I have updated the Google API, and have changed a number of settings and references to no avail.

I have no idea what is missing or how to replace it. I know it happens when I call the connection method of the uploading class, but the exception is thrown after the code exits this method.

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Net;
    using System.Net.Http;
    using Google.Apis.Auth.OAuth2;
    using Google.Apis.Drive.v3;
    using Google.Apis.Drive.v3.Data;
    using Google.Apis.Services;
    using Google.Apis.Util.Store;
    using System.IO;
    using System.Threading;
    //using Google.Apis.Vision.v1;
    using System.Diagnostics;
    using System.Runtime.InteropServices;    

    namespace Rohl
    {
        public class DriveManager
        {
            static string[] Scopes = { DriveService.Scope.Drive};
            static string ApplicationName = "Rohl - Drive Services";
            UserCredential credential;

            public void connector()
            {
                using (var stream = new FileStream("client_secret.json", FileMode.Open, FileAccess.Read))
                {
                    string credPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal);
                    credPath = Path.Combine(credPath, ".credentials/drive-dotnet-quickstart.json");


                    credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
                        GoogleClientSecrets.Load(stream).Secrets,
                        Scopes,
                        "user",
                        CancellationToken.None,
                        new FileDataStore(credPath, true)).Result;

                    Properties.Settings.Default.DebugWrite.Add(DateTime.Now.ToString("hh.mm.ss.ff") + " CREDENTIALS SAVED TO - " + credPath);
                }

                service = new DriveService(new BaseClientService.Initializer()
                {
                    HttpClientInitializer = credential,
                    ApplicationName = ApplicationName,
                });

            }
}
}

What am I missing that could cause the program to not be able to find the assembly?

Craig Key
  • 141
  • 4
  • 17
  • 1
    Have you visited this [SO post](https://stackoverflow.com/questions/20463119/the-system-cannot-find-the-file-specified)? Maybe this could help you eliminate the error. – MαπμQμαπkγVπ.0 Nov 12 '17 at 13:07

1 Answers1

1

Had exactly the same error on my project. I figured out that after the release the System.Net.Http.dll was missing in the folder where the .exe lies. Try to copy it from the bin\Debug-folder and see if this helps. Greetings.

Tue
  • 26
  • 1
  • This was the key, it now works for release builds. Now i just have to figure out how to include it in a published oneclick app. – Craig Key Nov 14 '17 at 15:39