【问题标题】:'Unable to find assembly 'System.Diagnostics.DiagnosticSource, Version=4.0.2.1 In MVC Visual Studio 2017 SignalR'无法在 MVC Visual Studio 2017 SignalR 中找到程序集'System.Diagnostics.DiagnosticSource,版本 = 4.0.2.1
【发布时间】:2019-07-04 10:05:38
【问题描述】:

'找不到程序集'System.Diagnostics.DiagnosticSource,版本=4.0.2.1 在 SignalR 中我发现了这个问题 'Unable to find assembly 'System.Diagnostics.DiagnosticSource, Version=4.0.2.1 in mvc Visula Studio 2017

在 SqlDependency.Start 中显示错误 System.Runtime.Serialization.SerializationException: '无法找到程序集 'System.Diagnostics.DiagnosticSource, Version=4.0.2.1, Culture=neutral, 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>
    <add name="DataBase" providerName="System.Data.SqlClient" connectionString="Data Source=DESKTOP-5I7L9G0\SEKHANISQL;Initial Catalog=SignalrMVC;Integrated Security=True" />
  </connectionStrings>

【问题讨论】:

  • 升级System.Net.Http 请找到升级链接nuget.org/packages/System.Net.Http
  • 我正在使用这个版本 System.Net.Http -Version 4.3.4,它是最新版本,但它不工作

标签: c# asp.net model-view-controller signalr sqldependency


【解决方案1】:

请检查您的 web.config 文件中的 连接字符串。 我希望它有帮助

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-10-21
    • 1970-01-01
    • 1970-01-01
    • 2018-03-23
    • 2016-08-16
    • 2018-05-24
    • 1970-01-01
    • 2018-12-14
    相关资源
    最近更新 更多