Home C# Mono NLog Could not load file or assembly When Deployed to Raspberry PI
Reply: 0

C# Mono NLog Could not load file or assembly When Deployed to Raspberry PI

user3203 Published in June 23, 2018, 9:20 pm

I have just begun messing with C# on my Raspberry Pi and it seems to be going well. I am developing my C# application on my Arch Linux machine with Monodevelop and scp-ing everything in the bin/Debug/ directory to my Raspberry Pi and then running "mono my.exe". This has worked with some simple applications I have played with but I am having trouble with NLog. The executable runs fine on my development machine but I get this exception on the Raspberry Pi:

mono NLogTest.exe 

Unhandled Exception:
System.TypeInitializationException: The type initializer for 'NLogTest.MainClass' threw an exception. ---> System.IO.FileNotFoundException: Could not load file or assembly or one of its dependencies.
  at NLog.LogFactory.get_Configuration () [0x000aa] in <eb9f75c9ffa040549f1fea1320a5bf6c>:0 
  at NLog.LogFactory.GetLogger (NLog.LogFactory+LoggerCacheKey cacheKey) [0x0012c] in <eb9f75c9ffa040549f1fea1320a5bf6c>:0 
  at NLog.LogFactory.GetLogger (System.String name) [0x00011] in <eb9f75c9ffa040549f1fea1320a5bf6c>:0 
  at NLog.LogManager.GetCurrentClassLogger () [0x0000a] in <eb9f75c9ffa040549f1fea1320a5bf6c>:0 
  at NLogTest.MainClass..cctor () [0x00000] in <689b8644ac61434f9d79427c3bf696a7>:0 
   --- End of inner exception stack trace ---

It seems as if NLog can't find the config file but it is in the same directory.

The simple example I am using is:

using System;
using NLog;
namespace NLogTest
    class MainClass
        private static Logger logger = LogManager.GetCurrentClassLogger();
        public static void Main(string[] args)
            Console.WriteLine("Testing NLog");
            logger.Trace("A Trace!!");
            logger.Debug("Sample debug message");
            logger.Info("Sample informational message");
            logger.Warn("Sample warning message");
            logger.Error("Sample error message");
            logger.Fatal("Sample fatal error message");
            Console.Write("DONE LOGGING!");

and my NLog.config file is pretty simple:

<?xml version="1.0" encoding="UTF-8" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
        <target xsi:type="File"
        <logger name="*" writeTo="logFile" minlevel="Info" />

The directory on my Raspberry Pi contains the exe, the NLog.config file, and the NLog.dll.

I installed the mono-runtime package from apt on the Raspberry pi. On my development machine, the Monodevelop build options for the project are set to target "Mono/.NET 4.5". I didn't think it would matter that I am developing on an x86 machine and deploying to an ARM-A machine because I thought the mono runtime would handle the architecture differences.

Any help here would be appreciated, thanks.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.647195 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO