1

I'm trying to upload a file to dropbox. The file gets uploaded and code works when i'm running locally. But file never gets uploaded when published on the server. I'm having the following error .

Could not load type 'System.Security.Authentication.SslProtocols' from assembly 'System.Net.Primitives, Version=4.0.0.0, Culture=neutral, PublicKeyToken=*********'.

I'm trying the below code sample to upload it

public sub uploadtodropbox()
  Using httpclient As New HttpClient
                        httpclient.Timeout = TimeSpan.FromMinutes(20)
                        Dim _DropboxClient = New DropboxClient(ApiKeyDropBox, config)
                        Dim resultstring As String = UploadToDB(_DropboxClient, dropboxdir, docName, fileBytes)
                        _DropboxClient.Dispose()
                        If Not resultstring = "RanToCompletion" Then
                            ErrorMsg &= "The following error occured: " & resultstring
                        End If
                    End Using                    

End Sub

and this is the funtion that is uploading to Dropbox

Private Function UploadToDB(_DropboxClient As DropboxClient, Directory As String, Filename As String, Content As [Byte]()) As String
    Try
        Dim result As String = "Unknown"
        Dim trycnt As String = 0
        Dim tryLimit As String = 20
        Dim respnse As Task(Of FileMetadata)
        Using _mStream = New MemoryStream(Content)
            respnse = _DropboxClient.Files.UploadAsync(Convert.ToString(Directory & Convert.ToString("/")) & Filename, WriteMode.Overwrite.Instance, body:=_mStream)
            While Not respnse.IsCompleted And trycnt < tryLimit
                Threading.Thread.Sleep(1000)
                trycnt += 1
                result = respnse.Status.ToString()
            End While
            UploadToDB = result
        End Using

End try END function.

I have tried without using the httpclient then i am getting this error :

The type initializer for 'Dropbox.Api.DropboxRequestHandlerOptions' threw an exception.

Thank you

LReddy
  • 117
  • 17
  • Can you share the full exception/stack? – Greg Feb 06 '17 at 18:10
  • 1
    Also, maybe you want to `await` the `UploadAsync` call so you don't have to do that sleep loop. – Greg Feb 06 '17 at 18:12
  • This is the exeption **The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel.** . I have tired the await for async but i'm using the method which is not async. Si, i need to work around it. – LReddy Feb 06 '17 at 19:13
  • Now, I was testing other case scenarios. I came to see that if i ran i for first time it executes or else it give the exception. Same as above situation – LReddy Feb 06 '17 at 19:17
  • It sounds like something is interfering with the TLS connection. There's a post here that may be helpful: https://stackoverflow.com/questions/703272/could-not-establish-trust-relationship-for-ssl-tls-secure-channel-soap – Greg Feb 06 '17 at 19:47
  • Thank @Greg I tried all those . But still the logic works fine in the localhost but when i Publish it on server. It is not uploading . I have published in on two different servers . both have the same issue. – LReddy Feb 06 '17 at 21:53
  • i got one more error @Greg Can you help with it Could not load type 'System.Security.Authentication.SslProtocols' from assembly 'System.Net.Primitives, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. – LReddy Feb 10 '17 at 14:17
  • That error itself doesn't seem related to Dropbox so I'm afraid I can't offer help with that. Try opening a new question with details to see if anyone can help. – Greg Feb 10 '17 at 17:53

1 Answers1

0

I go the answer . I have system.Net.primitives assembly that is creating a problem uploading the file to Dropbox. All i need to do is delete the reference and also the System.Net.Http has versions have been set wrong in the web.config file. Once i set that in the configuration everything works fine.

For the certificate I have set the on post back to validate and allow the certificates generated in the event handler.

LReddy
  • 117
  • 17