Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Peter Laurie 42 posts 116 karma points
    Jun 16, 2022 @ 07:34
    Peter Laurie
    0

    IContentFinder error - Cannot implicitly convert type 'bool' to 'system.threading.tasks.task bool'

    Hi, I have upgraded to Umbraco 10, and it seems the only issue I have encountered so far is down to the IContentFinder. I followed the example here, for our Umbraco 9 build: https://our.umbraco.com/documentation/reference/routing/request-pipeline/icontentfinder Now that we have upgraded to Umbraco 10, I have changed:

    public bool TryFindContent(IPublishedRequestBuilder contentRequest)
    

    which was fine in Umbraco 9, to:

    public Task<bool> TryFindContent(IPublishedRequestBuilder contentRequest)
    

    as per the example. Now I am getting the error in Visual studio which is preventing compiling the website build:

    with return false, Visual Studio says:

    Cannot implicitly convert type 'bool' to 'system.threading.tasks.task bool'

    I tried adding async:

    public async Task<bool> TryFindContent(IPublishedRequestBuilder contentRequest)
    

    Then I have the message:

    This async method lacks await operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...) to do CPU-bound work on a background thread

    Then it gives options to remove async (so were back to square one)

    Does anyone have ideas of the solution to this please. Do the documentation team need to be informed?

    Kind regards,

    Pete

  • Keith 74 posts 240 karma points
    Jun 17, 2022 @ 08:47
    Keith
    0

    Yeah, I think the documentation is wrong. I haven't tried this, but I think the issue is:

    Without the "async", the return type of "TryFindContent" is Task<bool>, not bool.

    So when returning values, the example in the documentation should change things like this:

    return false;
    

    to things like this:

    return Task.FromResult(false);
    
Please Sign in or register to post replies

Write your reply to:

Draft