NLog causing failure when remoting to server
See original GitHub issueNLog version: NLog 4.6.5
Platform: .Net 4.7
Hi,
When using Remoting NLog requires the remoting server to have a reference to NLog or else it will throw an exception.
System.Runtime.Serialization.SerializationException: Unable to find assembly 'NLog, Version=4.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c'.
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.__BinaryPar
ser.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.CoreChannel.DeserializeBinaryRequestMessage(String objectUri, Stream inputStream, Boolean bStrictBinding, TypeFilterLevel securityLevel)
at System.Runtime.Remoting.Channels.BinaryServerFormatterSink.ProcessMessage(IServerChannelSinkStack sinkStack, IMessage requestMsg, ITransportHeaders requestHeaders, Stream requestStream, IMessage& responseMsg, ITransportHeaders& responseHeaders, Stream& responseStream)
Exception rethrown at [0]:
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage r
etMsg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
at RemotingInterface.Foo.GetBar()
at RemotingClient.Controllers.FooController.GetBar() in C:\\Users\\oso\\Desktop\\lixo\\SimpleSample_Src\\RemotingClient\\Controllers\\FooController.cs:line 23
at lambda_method(Closure , Object , Object[] )
at Microsoft.Extensions.Internal.ObjectMethodExecutor.Execute(Object target, Object[] parameters)
at Microsoft.AspNetCore.Mvc.Internal.ActionMethodExecutor.SyncActionResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.<InvokeActionMethodAsync>d__12.MoveNext()
This happens because NLog uses System.Runtime.Remoting.Messaging.CallContext
instead of System.Threading.AsyncLocal<INestedContext>
for .NET 4.7 applications (there is no target framework > net45 built).
I created a sample application that shows this issue:
- Start the server;
- Start the Client
- Access http://localhost:5000/Foo
Issue Analytics
- State:
- Created 4 years ago
- Comments:6 (4 by maintainers)
Top Results From Across the Web
NLOG do not logs unhandled exceptions on server
I am experiencing following behavior: In development (local) there is no problem logging exceptions, all kind works. When I logged in remote ...
Read more >Config options for NLog's configuration
AutoFlushWrapper - Causes a flush after each write on a wrapped target. BufferingWrapper - A target that buffers log events and sends them...
Read more >NLog SeqTarget throwing an exception - Seq Documentation
I'm testing out Seq and I ran into a problem where the following exception occurs when we run a specific code path that...
Read more >Remote rsyslog only writing logging data to /var/log/syslog ...
I have two Windows Server 2008 boxes that each have a C# application using NLog.Targets.Syslog which log their debugging data to a linux...
Read more >NET Logging Best Practices and Tools
NET has three main logging levels: Error: This is a level under reservation for critical events. These often cause the system to crash....
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@ogielee NLog 5.0 will fix this issue (NLog ver. 5.0-preview ready now). Then using NLog on client-side will not cause error on the server-side (if using remoting)
I guess a workaround is to setup your AspNetCore-application to have IncludeScopes=false until a better version of NLog arrives that can use AsyncLocal on net472 (along with portable pdb-symbols-support).
https://github.com/NLog/NLog.Extensions.Logging/wiki/NLog-LoggerProvider-Options
Another work-around is to use NLog in the Server-application.
Yet another work-around is to have a dedicated thread that performs system-remoting calls. Instead of calling directly from ASP.NET.Core-threads then push to a queue. And have a dedicated-long-living-thread that monitors this queues and performs the system-remoting-calls. The dedicated thread will then not be “polluted” by the BeginScope-calls performed by the ASP.NET.Core-threads.
When adding a new targetplatform to NLog, then we also need to unit test this platform. And it would be nice if some could be removed as well (Ex Xamarin iOS + Xamarin Android + Silverlight + WindowsPhone + net40). But removing targetplatform would require major-version-jump to NLog5.