Answered by:
Cannot implicitly convert type 'System.Threading.Tasks.Task<object>' to 'string'

Question
-
User932259438 posted
Hi,
Do you have any idea?
I got this error: Cannot implicitly convert type 'System.Threading.Tasks.Task<object>' to 'string' in line:return context.Clients.All.RecieveNotification(totalNewMessages);
public string SendNotifications() { using (var connection = new SqlConnection(ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString)) { string query = "SELECT NewMessageCount FROM [dbo].[Modeling_NewMessageNotificationCount]"; connection.Open(); using (SqlCommand command = new SqlCommand(query, connection)) { try { command.Notification = null; DataTable dt = new DataTable(); SqlDependency dependency = new SqlDependency(command); dependency.OnChange += new OnChangeEventHandler(dependency_OnChange); if (connection.State == ConnectionState.Closed) connection.Open(); var reader = command.ExecuteReader(); dt.Load(reader); if (dt.Rows.Count > 0) { totalNewMessages =Int16.Parse(dt.Rows[0]["NewMessageCount"].ToString()); // totalNewCircles = Int16.Parse(dt.Rows[0]["NewCircleRequestCount"].ToString()); // totalNewJobs = Int16.Parse(dt.Rows[0]["NewJobNotificationsCount"].ToString()); // totalNewNotification = Int16.Parse(dt.Rows[0]["NewNotificationsCount"].ToString()); } connection.Close(); } catch(Exception ex) { throw; } } } IHubContext context = GlobalHost.ConnectionManager.GetHubContext<NotificationHub>(); return context.Clients.All.RecieveNotification(totalNewMessages); }
Friday, December 29, 2017 10:20 PM
Answers
-
User-484054684 posted
Hi,
It appears that the return type from the statement you posted is not a string and hence you get that error. You would need to understand whether you need to return anything from that method. If so, what do you want to return.
Please refer the following posts:
If you are following this tutorial - the code seems to be having the same issue. (See comments by people at the end of article) http://www.c-sharpcorner.com/UploadFile/raj1979/broadcast-sql-data-using-signalr-in-Asp-Net/
https://forums.asp.net/t/1981616.aspx?SignalR+Casting+Problem
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Sunday, December 31, 2017 9:55 AM
All replies
-
User932259438 posted
Still I need your help about this issue.
Saturday, December 30, 2017 8:34 PM -
User-484054684 posted
Hi,
It appears that the return type from the statement you posted is not a string and hence you get that error. You would need to understand whether you need to return anything from that method. If so, what do you want to return.
Please refer the following posts:
If you are following this tutorial - the code seems to be having the same issue. (See comments by people at the end of article) http://www.c-sharpcorner.com/UploadFile/raj1979/broadcast-sql-data-using-signalr-in-Asp-Net/
https://forums.asp.net/t/1981616.aspx?SignalR+Casting+Problem
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Sunday, December 31, 2017 9:55 AM