2017-12-22 4 views
0

하나의 솔루션에 두 개의 asp.net MVC 프로젝트가 있습니다. AdminPanel 및 웹. 나는 signalR을 사용하는 알림과 알림 테이블이 업데이트 될 때마다 알림을 표시해야합니다. 이 경우 signalR과 함께 SqlDependency를 사용하고 있습니다. 웹 프로젝트는 잘 실행하지만 관리 프로젝트 나에게이 오류여러 프로젝트에서 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 

이 하나 개의 시작 파일이 두 프로젝트

이 내에 messageHandler 클래스에서 사용하고있는도 구현을

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(); 
     } 
    } 
} 

이 모든 것이 정상적으로 작동합니다. 단,이 기능은 웹 프로젝트에서는 잘 작동하고 관리 프로젝트에서는 제대로 작동하지 않습니다.

답변

0

같은 문제가 있습니다. 해결책은 모든 프로젝트에서 System.Net.Http을 업그레이드하는 것이 었습니다.

이것은 nuget 명령입니다 : Update-Package System.Net.Http -Version 4.3.3 그리고 이것은 nuget 웹 페이지입니다 :

System.Net.Http nuget page 그것은 또한 당신의 문제를 해결하는 데 도움이 될 것입니다 바랍니다.

친절에 대해

+0

thankx. 나는 더 일찍 똑같은 일을했고 그것은 나를 위해 일했다. – zetawars

관련 문제