2017-12-22 21 views
0

私は2つのasp.net MVCプロジェクトを1つの解決策で持っています。 AdminPanelとWeb。私はsignalRを使用して通知を表示し、通知テーブルが更新されるたびに表示する必要があります。 私はこのためにsignalRと共にSqlDependencyを使用しています。 Webプロジェクトは、細かい実行されますが、管理プロジェクトは、私にこのエラー複数のプロジェクトでSignalRとSqlDependencyを使用する場合、アセンブリSystem.Diagnostics.DiagnosticSourceを見つけることができません

アセンブリを見つけることができません「System.Diagnostics.DiagnosticSourceを、バージョン= 4.0.2.1、文化=中立、なPublicKeyTokenは= cc7b13ffcd2ddd51」を提供します。ここで

スタックトレース

[SerializationException: Unable to find assembly 'System.Diagnostics.DiagnosticSource, Version=4.0.2.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'.] 
    System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg) +153 
    System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type) +336 
    System._AppDomain.CreateInstance(String assemblyName, String typeName) +0 
    System.Data.SqlClient.SqlDependency.CreateProcessDispatcher(_AppDomain masterDomain) +62 
    System.Data.SqlClient.SqlDependency.ObtainProcessDispatcher() +54 
    System.Data.SqlClient.SqlDependency.Start(String connectionString, String queue, Boolean useDefaults) +1095 
    System.Data.SqlClient.SqlDependency.Start(String connectionString) +13 
    HelperForYourHome.Admins.Hubs.Startup.Configuration(IAppBuilder app) in C:\Users\user\Documents\Projects\HelperForYourHome\HelperForYourHome.Admin\Hubs\Startup.cs:26 

[TargetInvocationException: Exception has been thrown by the target of an invocation.] 
    System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor) +0 
    System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments) +150 
    System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) +101 
    Owin.Loader.<>c__DisplayClass12.<MakeDelegate>b__b(IAppBuilder builder) +66 
    Owin.Loader.<>c__DisplayClass1.<LoadImplementation>b__0(IAppBuilder builder) +123 
    Microsoft.Owin.Host.SystemWeb.<>c__DisplayClass2.<InitializeBlueprint>b__0(IAppBuilder builder) +71 
    Microsoft.Owin.Host.SystemWeb.OwinAppContext.Initialize(Action`1 startup) +462 
    Microsoft.Owin.Host.SystemWeb.OwinBuilder.Build(Action`1 startup) +40 
    Microsoft.Owin.Host.SystemWeb.OwinHttpModule.InitializeBlueprint() +70 
    System.Threading.LazyInitializer.EnsureInitializedCore(T& target, Boolean& initialized, Object& syncLock, Func`1 valueFactory) +115 
    Microsoft.Owin.Host.SystemWeb.OwinHttpModule.Init(HttpApplication context) +106 
    System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers) +536 
    System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context) +173 
    System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) +336 
    System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) +296 

[HttpException (0x80004005): Exception has been thrown by the target of an invocation.] 
    System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +10042604 
    System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +95 
    System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +254 

はこの1つのスタートアップファイルが、これは私のMessageHandlerのクラスで両方のプロジェクトによって

を使用しているimplimentation

Owinスタートアップ

[assembly: OwinStartup("Startup", typeof(Startup))] 
namespace Admins.Hubs 
{ 
    public class Startup 
    { 
     public void Configuration(IAppBuilder app) 
     { 
      var idProvider = new CustomUserIdProvider(); 
      GlobalHost.DependencyResolver.Register(typeof(IUserIdProvider),() => idProvider); 
      app.MapSignalR(); 
      SqlDependency.Start(Connection.ConnectionString); 

      var properties = new AppProperties(app.Properties); 
      CancellationToken token = properties.OnAppDisposing; 
      if (token != CancellationToken.None) 
      { 
       token.Register(() => 
       { 
        SqlDependency.Stop(Connection.ConnectionString); 
       }); 
      } 
     } 
    } 
} 

です

public class MessagesRepository 
{ 
    readonly string _connString = Connection.ConnectionString; 
    public IEnumerable<NotificationMessage> GetAllMessages() 
    { 
     var messages = new List<NotificationMessage>(); 
     using (var connection = new SqlConnection(_connString)) 
     { 
      connection.Open(); 
      using (var command = new SqlCommand(@"SELECT [ID],[Title],[Description],[MessageType],[NotificationType],[Icon],[IsAjaxMessage],[IsViewMessage],[IsRedirectMessage] FROM [General].[NotificationMessage]", connection)) 
      { 
       command.Notification = null; 
       var dependency = new SqlDependency(command); 
       dependency.OnChange += new OnChangeEventHandler(dependency_OnChange); 
       if (connection.State == ConnectionState.Closed) 
        connection.Open(); 
       var reader = command.ExecuteReader(); 
       while (reader.Read()) 
       { 
        messages.Add(new NotificationMessage(reader)); 
       } 
      } 
     } 
     return messages; 
    } 



    public virtual void dependency_OnChange(object sender, SqlNotificationEventArgs e) 
    { 
     if (e.Type == SqlNotificationType.Change) 
     { 
      IHubContext context = GlobalHost.ConnectionManager.GetHubContext<Notification>(); 
      context.Clients.All.GetNotifications(); 
     } 
    } 
} 

これはすべて正常に動作しています。これはWebプロジェクトのみで、管理プロジェクトでは機能しません。

答えて

0

私は同じ問題があります。解決策はすべて私のプロジェクトでSystem.Net.Httpをアップグレードすることでした。

これはnugetコマンドです:Update-Package System.Net.Http -Version 4.3.3 そして、これはnugetウェブページです:

System.Net.Http nuget pageが、それはまたあなたの問題を解決するのに役立ちます願っています。

種類について

+0

感謝します。私は以前は同じことをしていたし、私のために働いた。 – zetawars

関連する問題