NLog.Config raising errors when running .NET code in Mono (on Ubuntu)?

Created on 1 Mar 2018  路  5Comments  路  Source: NLog/NLog

Hi,
I have come across very strange issue with NLog.

  1. .NET code in Mono, runs fine on CentOS.
  2. However the same code in Mono, when ran on Ubuntu; fails to run.
    Tried upgrading NLog, but didn't work.
  3. The errors are:
    Unhandled Exception:
NLog.NLogConfigurationException: Error when setting property 'Name' on File Target[(unnamed)] ---> System.ArgumentException: Object of type 'System.ReadOnlySpan`1[System.Char]' cannot be converted to type 'System.String'.
  at System.RuntimeType.CheckValue (System.Object value, System.Reflection.Binder binder, System.Globalization.CultureInfo culture, System.Reflection.BindingFlags invokeAttr) [0x00071] in <9689214c1e4645be91df75196bac3cbb>:0 
  at System.Reflection.MonoMethod.ConvertValues (System.Reflection.Binder binder, System.Object[] args, System.Reflection.ParameterInfo[] pinfo, System.Globalization.CultureInfo culture, System.Reflection.BindingFlags invokeAttr) [0x00069] in <9689214c1e4645be91df75196bac3cbb>:0 
  at System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00011] in <9689214c1e4645be91df75196bac3cbb>:0 
  at System.Reflection.MonoProperty.SetValue (System.Object obj, System.Object value, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] index, System.Globalization.CultureInfo culture) [0x0005d] in <9689214c1e4645be91df75196bac3cbb>:0 
  at System.Reflection.PropertyInfo.SetValue (System.Object obj, System.Object value, System.Object[] index) [0x00000] in <9689214c1e4645be91df75196bac3cbb>:0 
  at NLog.Internal.PropertyHelper.SetPropertyFromString (System.Object o, System.String name, System.String value, NLog.Config.ConfigurationItemFactory configurationItemFactory) [0x0012c] in <aaa5be9ae6074d46968bf6f374209e8d>:0 
   --- End of inner exception stack trace ---
  at NLog.Internal.PropertyHelper.SetPropertyFromString (System.Object o, System.String name, System.String value, NLog.Config.ConfigurationItemFactory configurationItemFactory) [0x001c7] in <aaa5be9ae6074d46968bf6f374209e8d>:0 
  at NLog.Config.XmlLoggingConfiguration.ConfigureObjectFromAttributes (System.Object targetObject, NLog.Config.NLogXmlElement element, System.Boolean ignoreType) [0x00057] in <aaa5be9ae6074d46968bf6f374209e8d>:0 
  at NLog.Config.XmlLoggingConfiguration.ParseTargetElement (NLog.Targets.Target target, NLog.Config.NLogXmlElement targetElement) [0x0000f] in <aaa5be9ae6074d46968bf6f374209e8d>:0 
  at NLog.Config.XmlLoggingConfiguration.ParseTargetsElement (NLog.Config.NLogXmlElement targetsElement) [0x001c2] in <aaa5be9ae6074d46968bf6f374209e8d>:0 
  at NLog.Config.XmlLoggingConfiguration.ParseNLogElement (NLog.Config.NLogXmlElement nlogElement, System.String baseDirectory) [0x00254] in <aaa5be9ae6074d46968bf6f374209e8d>:0 
  at NLog.Config.XmlLoggingConfiguration.ParseTopLevel (NLog.Config.NLogXmlElement content, System.String baseDirectory) [0x0005b] in <aaa5be9ae6074d46968bf6f374209e8d>:0 
  at NLog.Config.XmlLoggingConfiguration.Initialize (System.Xml.XmlReader reader, System.String fileName, System.Boolean ignoreErrors) [0x000b0] in <aaa5be9ae6074d46968bf6f374209e8d>:0 
  at NLog.Config.XmlLoggingConfiguration..ctor (System.String fileName) [0x00020] in <aaa5be9ae6074d46968bf6f374209e8d>:0 
  at NLog.LogFactory.LoadLoggingConfiguration (System.String configFile) [0x00018] in <aaa5be9ae6074d46968bf6f374209e8d>:0 
  at NLog.LogFactory.get_Configuration () [0x00092] in <aaa5be9ae6074d46968bf6f374209e8d>:0 
  at NLog.LogFactory.GetLogger (NLog.LogFactory+LoggerCacheKey cacheKey) [0x001b3] in <aaa5be9ae6074d46968bf6f374209e8d>:0 
  at NLog.LogFactory.GetLogger (System.String name) [0x00012] in <aaa5be9ae6074d46968bf6f374209e8d>:0 
  at NLog.LogManager.GetCurrentClassLogger () [0x0000b] in <aaa5be9ae6074d46968bf6f374209e8d>:0 
  at Vyopta.vAnalytics.Console.Program.ProcessOpts (System.String[] args) [0x00000] in <c4e44f1ab14742cbaaa48f9f845b66dd>:0 
  at Vyopta.vAnalytics.Console.Program.Main (System.String[] args) [0x00000] in <c4e44f1ab14742cbaaa48f9f845b66dd>:0 
[ERROR] FATAL UNHANDLED EXCEPTION: NLog.NLogConfigurationException: Error when setting property 'Name' on File Target[(unnamed)] ---> System.ArgumentException: Object of type 'System.ReadOnlySpan`1[System.Char]' cannot be converted to type 'System.String'.
  at System.RuntimeType.CheckValue (System.Object value, System.Reflection.Binder binder, System.Globalization.CultureInfo culture, System.Reflection.BindingFlags invokeAttr) [0x00071] in <9689214c1e4645be91df75196bac3cbb>:0 
  at System.Reflection.MonoMethod.ConvertValues (System.Reflection.Binder binder, System.Object[] args, System.Reflection.ParameterInfo[] pinfo, System.Globalization.CultureInfo culture, System.Reflection.BindingFlags invokeAttr) [0x00069] in <9689214c1e4645be91df75196bac3cbb>:0 
  at System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00011] in <9689214c1e4645be91df75196bac3cbb>:0 
  at System.Reflection.MonoProperty.SetValue (System.Object obj, System.Object value, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] index, System.Globalization.CultureInfo culture) [0x0005d] in <9689214c1e4645be91df75196bac3cbb>:0 
  at System.Reflection.PropertyInfo.SetValue (System.Object obj, System.Object value, System.Object[] index) [0x00000] in <9689214c1e4645be91df75196bac3cbb>:0 
  at NLog.Internal.PropertyHelper.SetPropertyFromString (System.Object o, System.String name, System.String value, NLog.Config.ConfigurationItemFactory configurationItemFactory) [0x0012c] in <aaa5be9ae6074d46968bf6f374209e8d>:0 
   --- End of inner exception stack trace ---
  at NLog.Internal.PropertyHelper.SetPropertyFromString (System.Object o, System.String name, System.String value, NLog.Config.ConfigurationItemFactory configurationItemFactory) [0x001c7] in <aaa5be9ae6074d46968bf6f374209e8d>:0 
  at NLog.Config.XmlLoggingConfiguration.ConfigureObjectFromAttributes (System.Object targetObject, NLog.Config.NLogXmlElement element, System.Boolean ignoreType) [0x00057] in <aaa5be9ae6074d46968bf6f374209e8d>:0 
  at NLog.Config.XmlLoggingConfiguration.ParseTargetElement (NLog.Targets.Target target, NLog.Config.NLogXmlElement targetElement) [0x0000f] in <aaa5be9ae6074d46968bf6f374209e8d>:0 
  at NLog.Config.XmlLoggingConfiguration.ParseTargetsElement (NLog.Config.NLogXmlElement targetsElement) [0x001c2] in <aaa5be9ae6074d46968bf6f374209e8d>:0 
  at NLog.Config.XmlLoggingConfiguration.ParseNLogElement (NLog.Config.NLogXmlElement nlogElement, System.String baseDirectory) [0x00254] in <aaa5be9ae6074d46968bf6f374209e8d>:0 
  at NLog.Config.XmlLoggingConfiguration.ParseTopLevel (NLog.Config.NLogXmlElement content, System.String baseDirectory) [0x0005b] in <aaa5be9ae6074d46968bf6f374209e8d>:0 
  at NLog.Config.XmlLoggingConfiguration.Initialize (System.Xml.XmlReader reader, System.String fileName, System.Boolean ignoreErrors) [0x000b0] in <aaa5be9ae6074d46968bf6f374209e8d>:0 
  at NLog.Config.XmlLoggingConfiguration..ctor (System.String fileName) [0x00020] in <aaa5be9ae6074d46968bf6f374209e8d>:0 
  at NLog.LogFactory.LoadLoggingConfiguration (System.String configFile) [0x00018] in <aaa5be9ae6074d46968bf6f374209e8d>:0 
  at NLog.LogFactory.get_Configuration () [0x00092] in <aaa5be9ae6074d46968bf6f374209e8d>:0 
  at NLog.LogFactory.GetLogger (NLog.LogFactory+LoggerCacheKey cacheKey) [0x001b3] in <aaa5be9ae6074d46968bf6f374209e8d>:0 
  at NLog.LogFactory.GetLogger (System.String name) [0x00012] in <aaa5be9ae6074d46968bf6f374209e8d>:0 
  at NLog.LogManager.GetCurrentClassLogger () [0x0000b] in <aaa5be9ae6074d46968bf6f374209e8d>:0 
  at Vyopta.vAnalytics.Console.Program.ProcessOpts (System.String[] args) [0x00000] in <c4e44f1ab14742cbaaa48f9f845b66dd>:0 
  at Vyopta.vAnalytics.Console.Program.Main (System.String[] args) [0x00000] in <c4e44f1ab14742cbaaa48f9f845b66dd>:0 

NLog.config is as below:
NLog.config.txt
Renamed to txt type, as .config file didn't work for attachment.

bug duplicate

Most helpful comment

Duplicate of #2598. Either update to NLog 4.4.13:

https://www.nuget.org/packages/NLog/4.4.13

Or NLog 4.5-rc06 (If using NLog 5.0):

https://www.nuget.org/packages/NLog/4.5.0-rc06

The problem comes when updating to mono 5.10 (from mono 5.8 or older).

All 5 comments

Duplicate of #2598. Either update to NLog 4.4.13:

https://www.nuget.org/packages/NLog/4.4.13

Or NLog 4.5-rc06 (If using NLog 5.0):

https://www.nuget.org/packages/NLog/4.5.0-rc06

The problem comes when updating to mono 5.10 (from mono 5.8 or older).

I have updated to NLog 4.4.13, and i have mono 5.10.1.4, and Ubuntu, same problem.

2018-03-26 17:14:22.7020 Warn Error when setting property 'Name' on 'File Target[(unnamed)]' Exception: System.ArgumentException: Object of type 'System.ReadOnlySpan`1[System.Char]' cannot be converted to type 'System.String'.

Can I help diagnosing this in any way?

@lestephane Would be surprised if you are the unique person in the world where NLog 4.4.13 is not working. I would double check if you have deployed the correct version of NLog, maybe validate the module/assembly-path in your application, and output the file-version.

I wiped out the nuget packages directory, all bin and objs directories, and rebuilt. It now works. Yay.

I initially upgraded the NLog version using Jetbrains Rider's nuget control window and did rebuild the solution. So i was a bit stomped that it still did not work. Now I know to double-check. I guess the issue should be closed.

This is fixed in 4.4.13 and 4.5, so closing this

Was this page helpful?
0 / 5 - 0 ratings

Related issues

BobSeu picture BobSeu  路  3Comments

geedsen picture geedsen  路  3Comments

imanushin picture imanushin  路  3Comments

MaximRouiller picture MaximRouiller  路  3Comments

ranjan-2209 picture ranjan-2209  路  3Comments