.NET Core Google Drive API works on windows but not on linux

2

Edit4: Bug in MCVE format

System.AggregateException in System.Net.Http.CurlHandler while using Google Drive API in dotnet core 2.0 in Ubuntu x64 Self Contained Deployment (SCD) without dotnet core runtime or curl installed

Expected Behavior:

Browser opens up with google login page

Exception:
    vm@vm-VirtualBox:/media/sf_Projects/test/mcve/bin/Release/netcoreapp2.0/ubuntu-x64/publish$ ./mcve

    Unhandled Exception: System.AggregateException: One or more errors occurred. (The type initializer for 'System.Net.Http.CurlHandler' threw an exception.) ---> System.TypeInitializationException: The type initializer for 'System.Net.Http.CurlHandler' threw an exception. ---> System.TypeInitializationException: The type initializer for 'Http' threw an exception. ---> System.TypeInitializationException: The type initializer for 'HttpInitializer' threw an exception. ---> System.DllNotFoundException: Unable to load DLL 'System.Net.Http.Native': The specified module or one of its dependencies could not be found.
     (Exception from HRESULT: 0x8007007E)
       at Interop.Http.GetSslVersionDescription()
       at Interop.HttpInitializer..cctor()
       --- End of inner exception stack trace ---
       at Interop.Http..cctor()
       --- End of inner exception stack trace ---
       at Interop.Http.GetSupportedFeatures()
       at System.Net.Http.CurlHandler..cctor()
       --- End of inner exception stack trace ---
       at System.Net.Http.CurlHandler..ctor()
       at System.Net.Http.HttpClientHandler..ctor()
       at Google.Apis.Http.HttpClientFactory.CreateSimpleClientHandler()
       at Google.Apis.Http.HttpClientFactory.CreateHandler(CreateHttpClientArgs args)
       at Google.Apis.Http.HttpClientFactory.CreateHttpClient(CreateHttpClientArgs args)
       at Google.Apis.Auth.OAuth2.Flows.AuthorizationCodeFlow..ctor(Initializer initializer)
       at Google.Apis.Auth.OAuth2.Flows.GoogleAuthorizationCodeFlow..ctor(Initializer initializer)
       at Google.Apis.Auth.OAuth2.GoogleWebAuthorizationBroker.<AuthorizeAsync>d__4.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at Google.Apis.Auth.OAuth2.GoogleWebAuthorizationBroker.<AuthorizeAsync>d__1.MoveNext()
       --- End of inner exception stack trace ---
       at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)
       at mcve.Program.Main(String[] args) in C:\Work\Projects\test\mcve\Program.cs:line 20

How to produces the problem?

  • Create a dotnet core 2.0 console application.
  • copy mcve.csprog

    <Project Sdk="Microsoft.NET.Sdk">
    
      <PropertyGroup>
        <OutputType>Exe</OutputType>
        <TargetFramework>netcoreapp2.0</TargetFramework>
      </PropertyGroup>
    
      <ItemGroup>
        <PackageReference Include="Google.Apis.Drive.v3" Version="1.35.1.1312" />
      </ItemGroup>
    
      <ItemGroup>
        <None Update="client_secret.json">
          <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
        </None>
      </ItemGroup>
    
    </Project>
    
  • copy Program.cs

    using System;
    using System.IO;
    using System.Threading;
    using Google.Apis.Auth.OAuth2;
    using Google.Apis.Drive.v3;
    using Google.Apis.Services;
    using Google.Apis.Util.Store;
    
    namespace mcve
    {
        class Program
        {
    
            private static string[] Scopes = new string[] { DriveService.Scope.Drive};
    
    
            static void Main(string[] args)
            {
    
                var stream = new FileStream("client_secret.json", FileMode.Open, FileAccess.Read);
    
                var credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
                       GoogleClientSecrets.Load(stream).Secrets,
                       Scopes,
                       "user",
                       CancellationToken.None,
                       new FileDataStore("credentials", true)).Result;
    
    
                stream.Close();
            }
        }
    }
    
  • You will require client_secret.json which you can download from here

  • copy client_secret.json in the project folder
  • compile the program using this command dotnet publish -c Release -f netcoreapp2.0 -r ubuntu-x64
  • now when the binaries are compiled, run it in a fresh install of ubuntu



Repository:

https://github.com/adsau59/DriveSoftwarePublisher

So I am making a software publisher that uses Google Drive, I used dotnet core thinking that it could be ported to linux and mac easily, so after I completed coding and testing or windows, I tried to test it on linux (linuxmint), but it didn't work and I'm getting an exception that I dont understand.

I'm using dotnet core 2.0

Exception Image:

https://s22.postimg.cc/8d0i0pmyp/Screenshot_from_2018-07-26_16-19-13.png

Prototype demo:

https://youtu.be/TdtkTxmOgw8

Binaries:

linux: https://drive.google.com/open?id=1gOdqr_TAx3QI1tRsWQe1mdpNOdBq5w54
windows: https://drive.google.com/open?id=1BP3ZsUmgri2oYKTOARxzoyS80Qe_rBt3

Edit:

Nuget packages https://s22.postimg.cc/4ezwpdkmp/image.png

Edit 2:
adam@Y50-Linux ~/Desktop/DriveSP_v0.1.0-alpha_ubuntu.16.10-x64 $ ./Publisher init test1

Unhandled Exception: System.AggregateException: One or more errors occurred. (The type initializer for 'System.Net.Http.CurlHandler' threw an exception.) ---> System.TypeInitializationException: The type initializer for 'System.Net.Http.CurlHandler' threw an exception. ---> System.TypeInitializationException: The type initializer for 'Http' threw an exception. ---> System.TypeInitializationException: The type initializer for 'HttpInitializer' threw an exception. ---> System.DllNotFoundException: Unable to load DLL 'System.Net.Http.Native': The specified module or one of its dependencies could not be found.
 (Exception from HRESULT: 0x8007007E)
   at Interop.Http.GetSslVersionDescription()
   at Interop.HttpInitializer..cctor()
   --- End of inner exception stack trace ---
   at Interop.Http..cctor()
   --- End of inner exception stack trace ---
   at Interop.Http.GetSupportedFeatures()
   at System.Net.Http.CurlHandler..cctor()
   --- End of inner exception stack trace ---
   at System.Net.Http.CurlHandler..ctor()
   at System.Net.Http.HttpClientHandler..ctor()
   at Google.Apis.Http.HttpClientFactory.CreateSimpleClientHandler()
   at Google.Apis.Http.HttpClientFactory.CreateHandler(CreateHttpClientArgs args)
   at Google.Apis.Http.HttpClientFactory.CreateHttpClient(CreateHttpClientArgs args)
   at Google.Apis.Auth.OAuth2.Flows.AuthorizationCodeFlow..ctor(Initializer initializer)
   at Google.Apis.Auth.OAuth2.Flows.GoogleAuthorizationCodeFlow..ctor(Initializer initializer)
   at Google.Apis.Auth.OAuth2.GoogleWebAuthorizationBroker.<AuthorizeAsync>d__4.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Google.Apis.Auth.OAuth2.GoogleWebAuthorizationBroker.<AuthorizeAsync>d__1.MoveNext()
   --- End of inner exception stack trace ---
   at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)
   at CommonScripts.Service..ctor(String secretPath, String credentialsJson) in D:\Projects\DriveSoftwarePublisher\CommonScripts\Service.cs:line 50
   at Publisher.Program.Main(String[] args) in D:\Projects\DriveSoftwarePublisher\Publisher\Program.cs:line 36
Aborted (core dumped)
Edit 3:

dotnet outdated

dotnet outdated results

c#
linux
google-drive-sdk
.net-core
asked on Stack Overflow Jul 28, 2018 by Adam Saudagar • edited Aug 21, 2018 by Adam Saudagar

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0