Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

282
Vistas
C# Await, null-coalescing, string interpolation does not compile

When conditionally awaiting a task using the null coalescing operator inside a string interpolation, I got an unexpected compilation error that my async method lacks an await, and that await isn't possible outside of an async context:

using System;
using System.Threading.Tasks;
                    
public class Program
{
    public static async Task Main()
    {
        Task<string> isNull = null;
        var result = "World";
        var helloWorld = $"Hello {await (isNull ?? Task.FromResult(result))}";
        Console.WriteLine(helloWorld);
    }
}
Compilation error (line 10, col 29): The name 'await' does not exist in the current context
Compilation error (line 6, col 27): 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.

I assume this is due to some compilator details that I am not aware of, and can't be avoided, but I would like to understand it.

Link to fiddle describing issue

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

It looks like you encountered a roslyn bug: https://github.com/dotnet/roslyn/issues/39149

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda