cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
We love to hear how every person gets the most from Dropbox, and it seems everyone has a slightly different use for it - tell us yours here!

Dropbox API Support & Feedback

Find help with the Dropbox API from other developers.

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

CreateSharedLinkWithSettingsAsync Operation is not valid due to the current state of the object.

CreateSharedLinkWithSettingsAsync Operation is not valid due to the current state of the object.

mohamed_atia
Explorer | Level 3

Hello Everyone,

 

I am using the below code block to upload a file and get its shareable link, but I am getting the below exception on calling CreateSharedLinkWithSettingsAsync.

 

I am using Dropbox.Api, Version=6.10.3.0, Culture=neutral, PublicKeyToken=310f0e82fbb45d01

 

 

System.AggregateException: One or more errors occurred. ---> System.InvalidOperationException: Operation is not valid due to the current state of the object.
   at Dropbox.Api.Sharing.AlphaResolvedVisibility.AlphaResolvedVisibilityDecoder.Decode(String tag, IJsonReader reader)
   at Dropbox.Api.Stone.UnionDecoder`1.DecodeFields(IJsonReader reader)
   at Dropbox.Api.Stone.StructDecoder`1.Decode(IJsonReader reader)
   at Dropbox.Api.Sharing.VisibilityPolicy.VisibilityPolicyDecoder.SetField(VisibilityPolicy value, String fieldName, IJsonReader reader)
   at Dropbox.Api.Stone.StructDecoder`1.DecodeFields(IJsonReader reader)
   at Dropbox.Api.Stone.StructDecoder`1.Decode(IJsonReader reader)
   at Dropbox.Api.Stone.ListDecoder`1.TryReadArrayItem(IJsonReader reader, IDecoder`1 decoder, T& value)
   at Dropbox.Api.Stone.ListDecoder`1.Decode(IJsonReader reader, IDecoder`1 itemDecoder)
   at Dropbox.Api.Sharing.LinkPermissions.LinkPermissionsDecoder.SetField(LinkPermissions value, String fieldName, IJsonReader reader)
   at Dropbox.Api.Stone.StructDecoder`1.DecodeFields(IJsonReader reader)
   at Dropbox.Api.Stone.StructDecoder`1.Decode(IJsonReader reader)
   at Dropbox.Api.Sharing.FileLinkMetadata.FileLinkMetadataDecoder.SetField(FileLinkMetadata value, String fieldName, IJsonReader reader)
   at Dropbox.Api.Stone.StructDecoder`1.DecodeFields(IJsonReader reader)
   at Dropbox.Api.Sharing.SharedLinkMetadata.SharedLinkMetadataDecoder.Decode(String tag, IJsonReader reader)
   at Dropbox.Api.Stone.UnionDecoder`1.DecodeFields(IJsonReader reader)
   at Dropbox.Api.Stone.StructDecoder`1.Decode(IJsonReader reader)
   at Dropbox.Api.Stone.JsonReader.Read[T](String json, IDecoder`1 decoder)
   at Dropbox.Api.DropboxRequestHandler.<Dropbox-Api-Stone-ITransport-SendRpcRequestAsync>d__12`3.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at Bnsights.ServerManager.DropboxIt.<GetLink>d__16.MoveNext() in ***\DropboxIt.cs:line 68
   --- End of inner exception stack trace ---
   at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
   at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)
   at System.Threading.Tasks.Task`1.get_Result()
   at Bnsights.ServerManager.SqlBackup.DropboxIt(String filePath) in *******\SqlBackup.cs:line 590
   at Bnsights.ServerManager.SqlBackup.backgroundWorker1_DoWork(Object sender, DoWorkEventArgs e) in *******\SqlBackup.cs:line 438
   at System.ComponentModel.BackgroundWorker.OnDoWork(DoWorkEventArgs e)
   at System.ComponentModel.BackgroundWorker.WorkerThreadStart(Object argument)
---> (Inner Exception #0) System.InvalidOperationException: Operation is not valid due to the current state of the object.
   at Dropbox.Api.Sharing.AlphaResolvedVisibility.AlphaResolvedVisibilityDecoder.Decode(String tag, IJsonReader reader)
   at Dropbox.Api.Stone.UnionDecoder`1.DecodeFields(IJsonReader reader)
   at Dropbox.Api.Stone.StructDecoder`1.Decode(IJsonReader reader)
   at Dropbox.Api.Sharing.VisibilityPolicy.VisibilityPolicyDecoder.SetField(VisibilityPolicy value, String fieldName, IJsonReader reader)
   at Dropbox.Api.Stone.StructDecoder`1.DecodeFields(IJsonReader reader)
   at Dropbox.Api.Stone.StructDecoder`1.Decode(IJsonReader reader)
   at Dropbox.Api.Stone.ListDecoder`1.TryReadArrayItem(IJsonReader reader, IDecoder`1 decoder, T& value)
   at Dropbox.Api.Stone.ListDecoder`1.Decode(IJsonReader reader, IDecoder`1 itemDecoder)
   at Dropbox.Api.Sharing.LinkPermissions.LinkPermissionsDecoder.SetField(LinkPermissions value, String fieldName, IJsonReader reader)
   at Dropbox.Api.Stone.StructDecoder`1.DecodeFields(IJsonReader reader)
   at Dropbox.Api.Stone.StructDecoder`1.Decode(IJsonReader reader)
   at Dropbox.Api.Sharing.FileLinkMetadata.FileLinkMetadataDecoder.SetField(FileLinkMetadata value, String fieldName, IJsonReader reader)
   at Dropbox.Api.Stone.StructDecoder`1.DecodeFields(IJsonReader reader)
   at Dropbox.Api.Sharing.SharedLinkMetadata.SharedLinkMetadataDecoder.Decode(String tag, IJsonReader reader)
   at Dropbox.Api.Stone.UnionDecoder`1.DecodeFields(IJsonReader reader)
   at Dropbox.Api.Stone.StructDecoder`1.Decode(IJsonReader reader)
   at Dropbox.Api.Stone.JsonReader.Read[T](String json, IDecoder`1 decoder)
   at Dropbox.Api.DropboxRequestHandler.<Dropbox-Api-Stone-ITransport-SendRpcRequestAsync>d__12`3.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at Bnsights.ServerManager.DropboxIt.<GetLink>d__16.MoveNext() in *******\DropboxIt.cs:line 68<---

 

 

 

private string DropboxIt(string filePath)
        {
            var path = Upload(filePath).Result;
            var link = dropboxit.GetLink(path).Result;
            return link;
        }

public async Task<string> Upload(string filePath)
        {
            var fileNameWithExt = $"/{System.IO.Path.GetFileName(filePath)}";
            using (var dropboxClient = InitalizeClient())
            using (var stream = new FileStream(filePath, FileMode.Open))
            {
                var task = await dropboxClient.Files.UploadAsync(fileNameWithExt, WriteMode.Add.Instance, body: stream);
                return task.PathLower;
            }
        }
public async Task<string> GetLink(string path)
        {
            using (var dropboxClient = InitalizeClient())
            {
                var link = await dropboxClient.Sharing.ListSharedLinksAsync(path);
                if (link.Links.Count == 0)
                {
                    var result = await dropboxClient.Sharing.CreateSharedLinkWithSettingsAsync(path);
                    string url = result.Url;
                    return url;
                }
                else
                {
                    string url = link.Links[0].Url;
                    return url;
                }
            }
        }

private DropboxClient InitalizeClient()
        {
            var dropboxClient = new DropboxClient(this.AccessToken, new DropboxClientConfig
            {
                HttpClient = new HttpClient
                {
                    Timeout = TimeSpan.FromMinutes(RequestTimeout),
                }
            });

            return dropboxClient;
        }

 

 

1 Accepted Solution

Accepted Solutions

Re: CreateSharedLinkWithSettingsAsync Operation is not valid due to the current state of the object.

Greg-DB
Dropboxer

Thanks for the report! This is a known issue in the latest two versions of the Dropbox .NET SDK. Please downgrade to v6.10.1 of the SDK to avoid this for now.

View solution in original post

2 Replies 2

Re: CreateSharedLinkWithSettingsAsync Operation is not valid due to the current state of the object.

Greg-DB
Dropboxer

Thanks for the report! This is a known issue in the latest two versions of the Dropbox .NET SDK. Please downgrade to v6.10.1 of the SDK to avoid this for now.

View solution in original post

Re: CreateSharedLinkWithSettingsAsync Operation is not valid due to the current state of the object.

Greg-DB
Dropboxer

This should be fixed in the latest version now, v6.11.1.

Who's talking

Top contributors to this post

  • User avatar
    Greg-DB Dropboxer
What do Dropbox user levels mean?
Need more support?