Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

281
Views
C# Await, null-coalescing, la interpolación de cadenas no se compila

Cuando esperaba condicionalmente una tarea usando el operador de fusión nulo dentro de una interpolación de cadena, recibí un error de compilación inesperado que indicaba que mi método asíncrono carece de espera, y que esperar no es posible fuera de un contexto asíncrono:

 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.

Supongo que esto se debe a algunos detalles del compilador que desconozco y que no se pueden evitar, pero me gustaría entenderlo.

Enlace al violín que describe el problema

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Parece que encontró un error de roslyn: https://github.com/dotnet/roslyn/issues/39149

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!