Skip to content

Failed obtaining configuration for Common.Logging in dotnet versions #179

@robsosno

Description

@robsosno

Steps to reproduce:
Simple console application, Set properly LogConfiguration configuration from file or from strings.
Then:
LogManager.Configure(configuration);
log = LogManager.GetLogger(); <-- crashes

Stack trace:
Common.Logging.ConfigurationException
HResult=0x80131500
Message=Failed obtaining configuration for Common.Logging from configuration section 'common/logging'.
Source=Common.Logging
StackTrace:
at Common.Logging.Configuration.ArgUtils.Guard[T](Function`1 function, String messageFormat, Object[] args)
at Common.Logging.Configuration.ArgUtils.Guard(Action action, String messageFormat, Object[] args)
at Common.Logging.LogManager.BuildLoggerFactoryAdapter()
at Common.Logging.LogManager.get_Adapter()
at Common.Logging.LogManager.GetLoggerT
at TestOldFramework.Program.Main(String[] args) in d:\dokumenty\Visual Studio 2019\source\repos\Common.Logging.Ext\TestOldFramework\Program.cs:line 25

Inner Exception 1:
FileNotFoundException: Nie można załadować pliku lub zestawu 'System.Reflection.TypeExtensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' lub jednej z jego zależności. Nie można odnaleźć określonego pliku.
"Nie można załadować pliku lub zestawu" = "File or assembly could not be loaded"

Console application is in .Net 4.6.1 and Common.Logging is in Netstandard 1.3

An error occurs in ArgUtils.cs on following line:
if (!typeof(T).IsAssignableFrom(valType))
This is because NetStandard doesn't have IsAssignableFrom method and System.Reflection.TypeExtensions is used. However it cannot be loaded in .NET 4.6.1

Suggested solution:
#if DOTNETCORE
if (!typeof(T).GetTypeInfo().IsAssignableFrom(valType.GetTypeInfo()))
#else
if (!typeof(T).IsAssignableFrom(valType))
#endi

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions