none
there is no implicit conversion between 'System.Threading.Tasks.Task<string>' and 'string' RRS feed

  • Question

  • Hi, I got this error message, what should I do? 

    "Type of conditional expression cannot be determined because there is no implicit conversion between 'System.Threading.Tasks.Task<string>' and 'string'"

    Wednesday, October 2, 2019 7:29 PM

All replies

  • Please add your code in a code block so if someone wants to offer a modification they can do so without typing out the code in the image.

    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    Wednesday, October 2, 2019 7:56 PM
    Moderator
  • Hi sdnd2000,

    Thank you for posting here.

    For your question, the complier error caused by the ternary conditional operator(?:).

    When you use this operation, the type of "reponse.Content.ReadAsStringAsync()" and "reponse.StatusCode.ToString()" must be the same, or there must be an implicit conversion from one type to the other.

    Please try the code below, no complier error occures.

      return reponse.StatusCode == System.Net.HttpStatusCode.OK ? reponse.Content.ReadAsStringAsync().ToString() : reponse.StatusCode.ToString();

    Best Regards,

    Wendy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, October 3, 2019 2:38 AM
    Moderator
  • Try this too:

    return await ( response.StatusCode == System.Net.HttpStatusCode.OK ? response.Content.ReadAsStringAsync( ) : Task.FromResult( response.StatusCode.ToString( ) ) );

    Thursday, October 3, 2019 4:56 AM
  • Hello,

    Checking in to see if you still have questions or have resolved this issue.


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    Sunday, October 13, 2019 11:39 AM
    Moderator