O
O
Oleg Tarakanov2015-12-03 07:46:55
linux
Oleg Tarakanov, 2015-12-03 07:46:55

Why doesn't the console application work in Mono?

We are trying to run a simple console application that uses Log4Net (12.10) for its work.
Used AltLinux 6.0.1 and Mono 2.6.7, .Net Framework 3.5.
Here is the result of a normal "exhaust" on Windows:

F:\Work\Projects\Mono\Debug>Tool.exe
List of possible arguments:
Tool.exe [-CheckDB] [-CheckFreeSpace] [-BackupDB] [-ShrinkDB]
-CheckDB Check DB
-CheckFreeSpace Check if there is free space on the hard disk
-BackupDB Backup database
-BackupAttachments Backup attached files
-RemoveOldBackups Remove old backups
-RestoreLogConfig Restore logging configuration file
-ShrinkDB Clean up unused data

When running through mono, we immediately stumble on an error:
# sudo mono Tool.exe
Unhandled Exception: System.TypeInitializationException: An exception was thrown by the type initializer for Tool ---> Common.Logging.ConfigurationException: Unable to create type 'Common.Logging.Log4Net .Log4NetLoggerFactoryAdapter, Common.Logging.Log4net' ---> System.TypeLoadException: Could not load type 'Common.Logging.Log4Net.Log4NetLoggerFactoryAdapter, Common.Logging.Log4net'.
at (wrapper managed-to-native) System.Type:internal_from_name (string,bool,bool)
at System.Type.GetType (System.String typeName, Boolean throwOnError, Boolean ignoreCase) [0x00000] in :0
at Common.Logging. ConfigurationSectionHandler.ReadConfiguration (System.Xml.XmlNode section) [0x00000] in :0
--- End of inner exception stack trace ---
at Common.Logging.ConfigurationSectionHandler.ReadConfiguration (System.Xml.XmlNode section) [0x00000] in :0
at Common.Logging.ConfigurationSectionHandler.Create (Common.Logging.Configuration.LogSetting parent, System.Object configContext, System.Xml.XmlNode section) [0x00000] in :0
at Common.Logging.ConfigurationSectionHandler.System.Configuration.IConfigurationSectionHandler.Create (System.Object parent, System.Object configContext, System.Xml.XmlNode section) [0x00000] in :0
at System.Configuration .ConfigurationSection.GetRuntimeObject () [0x00000] in :0
at System.Configuration.ClientConfigurationSystem.System.Configuration.Internal.IInternalConfigSystem.GetSection (System.String configKey) [0x00000] in :0
at System.Configuration.ConfigurationManager.GetSection (System.String sectionName) [0x00000] in :0
at Common.Logging.Configuration.DefaultConfigurationReader.GetSection (System.String sectionName) [0x00000] in :0
at Common.Logging.LogManager+<> c__DisplayClass3.b__0 () [0x00000] in :0
at Common.Logging.Configuration.ArgUtils+<>c__DisplayClass13.b__12 () [0x00000] in :0
at Common.Logging.Configuration.ArgUtils.Guard[Int32] (Common.Logging. Configuration.Function`1 function, System.String messageFormat, System.Object[] args) [0x00000] in :0
--- End of inner exception stack trace ---

As I understand it, it is not possible to parse XML, namely the path to the file with the log4net configuration:
<?xml version="1.0" encoding="utf-8" ?>
...

The file itself is located in the same folder as the EXE.
If we disable log4net, then the application starts without any action:
[[email protected] Tool]# sudo mono --debug Tool.exe
[[email protected] Tool]#

If we pass the required parameter, we get an error:
# sudo mono --debug Tool.exe -CheckFreeSpace
??????: An exception was thrown by the type initializer for Tool.Factory

There is a fork in the code:
if (!(ConfigurationManager.GetSection("Config") is Config))
{
throw new ConfigurationErrorsException(Resource.ErrorConfiguration + Resource.ErrorConfigSectionIsWrongOrEmpty);
}
Config = (Config)ConfigurationManager.GetSection("Config");

Which indicates a crooked config, but we looked through it up and down - even if the connection strings to the database are crooked, it should start - the config scheme is not broken.
Please help with advice.

Answer the question

In order to leave comments, you need to log in

[[+comments_count]] answer(s)
O
Oleg Tarakanov, 2015-12-03
@druoleg

Problem solved by tweaking Mono source code and utility.
The program started after fixing two errors (on Mono 4.3.0):
1. one of the libraries was not connected correctly;
2. there was a typo in the config;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question