Error CS0433 A task type exists in both System.Threading and mscorlib

I get an error in this code:

public async Task SendEmailsTask(List<string> emails) { for (int i = 0; i < emails.Count; i++) { await Task.Delay(5000); } } 

Here is the error:

 Severity Code Description Project File Line Source Suppression State Error CS0433 The type 'Task' exists in both 'System.Threading, Version=1.0.2856.102, Culture=neutral, PublicKeyToken=31bf3856ad364e35' and 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' 
+5
source share
1 answer

The compiler does not know what task you have in mind, since it exists in two libraries. Either use the names of the full class ( System.Threading.Task SendEmailsTask ), or give the namespace an alias

 using myAlias = System.Threading.Tasks; 

And refer to it as

 public async myAlias.Task SendEmailsTask 
-3
source

Source: https://habr.com/ru/post/1238734/


All Articles