<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Newbie Question: Compiler error when going from sample to project. in Dropbox API Support &amp; Feedback</title>
    <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Newbie-Question-Compiler-error-when-going-from-sample-to-project/m-p/378128#M21193</link>
    <description>&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;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):&lt;/P&gt;&lt;PRE&gt;static void Main(string[] args) {
    var task = Task.Run((Func&amp;lt;Task&amp;gt;)Program.Run);
    task.Wait();
}

static async Task Run() {
    using (var dbx = new DropboxClient("MyAccessToken")) {
        await CreateFolder(dbx, "/2019-11-07");
        Console.ReadKey();
    }
}&lt;/PRE&gt;&lt;P&gt;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:&lt;/P&gt;&lt;PRE&gt;public int CreateFolder(string strPath, string FileName) {
    try {
        var task = Task.Run((Func&amp;lt;Task&amp;gt;)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);
    }
}&lt;/PRE&gt;&lt;P&gt;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&amp;lt;System.Threading.Tasks.Task&amp;gt;'&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;Any help would be appreciated and, like I said, if this is not appropriate for this forum just let me know.&lt;/P&gt;</description>
    <pubDate>Tue, 12 Nov 2019 19:58:40 GMT</pubDate>
    <dc:creator>malindor</dc:creator>
    <dc:date>2019-11-12T19:58:40Z</dc:date>
    <item>
      <title>Newbie Question: Compiler error when going from sample to project.</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Newbie-Question-Compiler-error-when-going-from-sample-to-project/m-p/378128#M21193</link>
      <description>&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;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):&lt;/P&gt;&lt;PRE&gt;static void Main(string[] args) {
    var task = Task.Run((Func&amp;lt;Task&amp;gt;)Program.Run);
    task.Wait();
}

static async Task Run() {
    using (var dbx = new DropboxClient("MyAccessToken")) {
        await CreateFolder(dbx, "/2019-11-07");
        Console.ReadKey();
    }
}&lt;/PRE&gt;&lt;P&gt;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:&lt;/P&gt;&lt;PRE&gt;public int CreateFolder(string strPath, string FileName) {
    try {
        var task = Task.Run((Func&amp;lt;Task&amp;gt;)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);
    }
}&lt;/PRE&gt;&lt;P&gt;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&amp;lt;System.Threading.Tasks.Task&amp;gt;'&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;Any help would be appreciated and, like I said, if this is not appropriate for this forum just let me know.&lt;/P&gt;</description>
      <pubDate>Tue, 12 Nov 2019 19:58:40 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Newbie-Question-Compiler-error-when-going-from-sample-to-project/m-p/378128#M21193</guid>
      <dc:creator>malindor</dc:creator>
      <dc:date>2019-11-12T19:58:40Z</dc:date>
    </item>
    <item>
      <title>Re: Newbie Question: Compiler error when going from sample to project.</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Newbie-Question-Compiler-error-when-going-from-sample-to-project/m-p/378135#M21194</link>
      <description>&lt;P&gt;It looks like this is more about managing tasks in .NET/C#, and not really about using the&amp;nbsp;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&amp;nbsp;advice, such as StackOverflow. Apologies I can't be more useful!&lt;/P&gt;</description>
      <pubDate>Tue, 12 Nov 2019 20:42:20 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Newbie-Question-Compiler-error-when-going-from-sample-to-project/m-p/378135#M21194</guid>
      <dc:creator>Greg-DB</dc:creator>
      <dc:date>2019-11-12T20:42:20Z</dc:date>
    </item>
    <item>
      <title>Re: Newbie Question: Compiler error when going from sample to project.</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Newbie-Question-Compiler-error-when-going-from-sample-to-project/m-p/378138#M21195</link>
      <description>&lt;P&gt;No worries.&amp;nbsp; I wasn't sure and doesn't hurt to ask.&amp;nbsp; Thanks for your time.&lt;/P&gt;</description>
      <pubDate>Tue, 12 Nov 2019 21:04:55 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Newbie-Question-Compiler-error-when-going-from-sample-to-project/m-p/378138#M21195</guid>
      <dc:creator>malindor</dc:creator>
      <dc:date>2019-11-12T21:04:55Z</dc:date>
    </item>
  </channel>
</rss>

