remoting - 使用远程处理时无法找到程序集 System.Diagnostics.DiagnosticSource

标签 remoting azure-application-insights .net-remoting

将 Application Insights 添加到我的 ASP.NET 应用程序(使用 .NET 4.5.2 的标准 ASP.NET)后,我发现在使用 .NET 远程处理时出现异常。异常(exception)是:

无法找到程序集“System.Diagnostics.DiagnosticSource,Version=4.0.2.1,Culture=neutral,PublicKeyToken=cc7b13ffcd2ddd51”

我不太明白这里发生了什么(看起来跟踪正在跨越应用程序域边界),但是如果我将 System.Diagnostics.DiagnosticSource NuGet 包添加到远程服务,错误就会消失。

不幸的是,我刚刚发现在尝试使用 SqlDependency 触发缓存刷新时也遇到了此错误。如果确实发生了这种情况,有没有办法在使用远程处理时禁用此跟踪,或者是否有其他方法可以解决此问题?

Server stack trace: 
   at System.Runtime.Serialization.Formatters.Binary.BinaryAssemblyInfo.GetAssembly()
   at System.Runtime.Serialization.Formatters.Binary.ObjectReader.GetType(BinaryAssemblyInfo assemblyInfo, String name)
   at System.Runtime.Serialization.Formatters.Binary.ObjectMap..ctor(String objectName, String[] memberNames, BinaryTypeEnum[] binaryTypeEnumA, Object[] typeInformationA, Int32[] memberAssemIds, ObjectReader objectReader, Int32 objectId, BinaryAssemblyInfo assemblyInfo, SizedArray assemIdToAssemblyTable)
   at System.Runtime.Serialization.Formatters.Binary.__BinaryParser.ReadObjectWithMapTyped(BinaryObjectWithMapTyped record)
   at System.Runtime.Serialization.Formatters.Binary.__BinaryParser.ReadObjectWithMapTyped(BinaryHeaderEnum binaryHeaderEnum)
   at System.Runtime.Serialization.Formatters.Binary.__BinaryParser.Run()
   at System.Runtime.Serialization.Formatters.Binary.ObjectReader.Deserialize(HeaderHandler handler, __BinaryParser serParser, Boolean fCheck, Boolean isCrossAppDomain, IMethodCallMessage methodCallMessage)
   at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(Stream serializationStream, HeaderHandler handler, Boolean fCheck, Boolean isCrossAppDomain, IMethodCallMessage methodCallMessage)
   at System.Runtime.Remoting.Channels.CrossAppDomainSerializer.DeserializeObject(MemoryStream stm)
   at System.Runtime.Remoting.Messaging.SmuggledMethodCallMessage.FixupForNewAppDomain()
   at System.Runtime.Remoting.Channels.CrossAppDomainSink.DoDispatch(Byte[] reqStmBuff, SmuggledMethodCallMessage smuggledMcm, SmuggledMethodReturnMessage& smuggledMrm)
   at System.Runtime.Remoting.Channels.CrossAppDomainSink.DoTransitionDispatchCallback(Object[] args)

Exception rethrown at [0]: 
   at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
   at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
   at System._AppDomain.CreateInstance(String assemblyName, String typeName)
   at System.Data.SqlClient.SqlDependency.CreateProcessDispatcher(_AppDomain masterDomain)
   at System.Data.SqlClient.SqlDependency.ObtainProcessDispatcher()
   at System.Data.SqlClient.SqlDependency.Start(String connectionString, String queue, Boolean useDefaults)

最佳答案

我通过升级到 System.Diagnostics.DiagnosticSource 4.5.0 修复了该问题

问题在于 Application Insights 创建 System.Diagnostics.Activity 的实例并将其存储在 CallContext (LogicalCallContext) 中。在远程调用期间,CallContext 被编码到远程服务器。不幸的是,这个 .dll 不存在。

就我而言,情况更糟,远程服务器是在 .NET 2.0 上运行的遗留应用程序,复制 dll 并没有解决问题。

您可以在https://github.com/Microsoft/ApplicationInsights-dotnet-server/issues/613找到更多相关信息。

关于remoting - 使用远程处理时无法找到程序集 System.Diagnostics.DiagnosticSource,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46204975/

相关文章:

c# - 将 .Net Remoting 从 Framework 2 迁移到 4 的问题

azure-application-insights - 什么是 MS App Insights 吞吐量?

azure - Application Insights 中的用户流和 channel 功能之间的差异

c# - 远程设置超时

c# - 对远程对象的方法调用永远不会返回 (.NET Remoting)

c# - 在.NET Remoting 中如何知道类方法是在内部调用还是远程调用?

java - 如何从 XFire AbstractHandler 的 invoke() 方法中获取 ServletRequest 对象?

c# - 将程序集加载到新的应用程序域并与 WCF 通信

java - 在不同远程对象之间拆分远程 EJB 功能

javascript - Azure Application Insight 会显示 JavaScript 错误吗?