«Невозможно найти сборку» System.Diagnostics.DiagnosticSource, версия = 4.0.2.1
В SignalR я обнаружил эту проблему «Невозможно найти сборку» System.Diagnostics.DiagnosticSource, версия = 4.0.2.1 в mvc Visula Studio 2017
в SqlDependency.Start показать ошибку System.Runtime.Serialization.SerializationException: «Невозможно найти сборку» System.Diagnostics.DiagnosticSource, версия = 4.0.2.1, культура = нейтральная, PublicKeyToken = cc7b13ffcd2ddd51 '.'
HomeController.cs
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Services;
using System.Web.UI.WebControls;
namespace SocketinMVC.Controllers
{
public class HomeController : Controller
{
public ActionResult Index()
{
return View();
}
public ActionResult About()
{
ViewBag.Message = "Your application description page.";
GetData();
return View();
}
public ActionResult Contact()
{
ViewBag.Message = "Your contact page.";
return View();
}
[WebMethod]
public static IEnumerable<Products> GetData()
{
using (var connection = new SqlConnection(System.Web.Configuration.WebConfigurationManager.ConnectionStrings["DataBase"].ConnectionString))
{
connection.Open();
using (SqlCommand command = new SqlCommand(@"SELECT [id],[back1],[lay1] FROM [SignalrMVC].[dbo].[test33]", connection))
{
// Make sure the command object does not already have
// a notification object associated with it.
command.Notification = null;
SqlDependency.Start(ConfigurationManager.ConnectionStrings["DataBase"].ConnectionString);
SqlDependency dependency = new SqlDependency(command);
dependency.OnChange += new OnChangeEventHandler(dependency_OnChange);
if (connection.State == ConnectionState.Closed)
connection.Open();
using (var reader = command.ExecuteReader())
return reader.Cast<IDataRecord>()
.Select(x => new Products()
{
id = x.GetInt32(0),
Back1 = x.GetString(1),
Lay1 = x.GetString(2)
}).ToList();
}
}
}
public static void dependency_OnChange(object sender, SqlNotificationEventArgs e)
{
MyHub.Show();
}
}
}
ConnectionStrings
<connectionStrings>
<add name="DataBase" providerName="System.Data.SqlClient" connectionString="Data Source=DESKTOP-5I7L9G0\SEKHANISQL;Initial Catalog=SignalrMVC;Integrated Security=True" />
</connectionStrings>