cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Want to know what we learned at IBC? Check out our learnings on media, remote working and more right 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: 

Re: Newbie Question: Compiler error when going from sample to project.

Newbie Question: Compiler error when going from sample to project.

malindor
New member | Level 2
Go to solution

I appolgize if this is not the correct forum for this question. As the issue came up working with the APIs here, I figured I would start here and go elsewhere if necessary.

I'm using the latest .NET dropbox.api library on VS 2019. I have been asked to create a in-house library for other developers to use until we can put together some in-house formal training for everyone on Dropbox's APIs. I've read through the documentation and the sample GitHub code. I reproduced the example and got it working. Everything's good. The working code (abridged for brevity):

static void Main(string[] args) {
    var task = Task.Run((Func<Task>)Program.Run);
    task.Wait();
}

static async Task Run() {
    using (var dbx = new DropboxClient("MyAccessToken")) {
        await CreateFolder(dbx, "/2019-11-07");
        Console.ReadKey();
    }
}

So I move on to starting to build a basic library and will add all the bells and whistles after getting a few functions to work. This is where the problem is. I created what I thought was a similar entry point but now I'm getting a compiler error The erroring code:

public int CreateFolder(string strPath, string FileName) {
    try {
        var task = Task.Run((Func<Task>)SoDropbox.CF(Path.Combine(strPath,FileName)));
        task.Wait();
    }
    catch(Exception e) {
        return -1;
    }
    return 1;
}

static async Task CF(string strPath) {
    using (var dbx = client) {
        var folderArg = new CreateFolderArg(Path);
        var folder = await dbx.Files.CreateFolderV2Async(folderArg);
    }
}

The error that I am getting is in the first line of the try block or the CreateFolder method. The error is: Cannot convert type 'System.Threading.Tasks.Task' to 'System.Func<System.Threading.Tasks.Task>'

I'm sure this has more to do with my lack of understanding of the Func delegate and asynchronous Tasks but I am not seeing what the difference is between the working code and the new code.

Any help would be appreciated and, like I said, if this is not appropriate for this forum just let me know.

1 Accepted Solution

Accepted Solutions

Greg-DB
Dropbox Staff
Go to solution

It looks like this is more about managing tasks in .NET/C#, and not really about using the Dropbox API itself, so I'm afraid I can't really be of help here. This question may be better suited somewhere where you can get general .NET/C# programming advice, such as StackOverflow. Apologies I can't be more useful!

View solution in original post

2 Replies 2

Greg-DB
Dropbox Staff
Go to solution

It looks like this is more about managing tasks in .NET/C#, and not really about using the Dropbox API itself, so I'm afraid I can't really be of help here. This question may be better suited somewhere where you can get general .NET/C# programming advice, such as StackOverflow. Apologies I can't be more useful!

malindor
New member | Level 2
Go to solution

No worries.  I wasn't sure and doesn't hurt to ask.  Thanks for your time.

Need more support?