.NET SDK 2.1.3 and Common.Logging - Use common.logging 3.1 not 3.2!


#1

I’ve noticed a weird quirk here. When I set the Common.Logging version to latest 3.2.0, the CouchbaseNet SDK crashes with a System.TypeInitializationException exception when constructing a ClientConfiguration, but if I drop Common.Logging version back to 3.1.0 everything is fine.

Just wanted to post this note in case anybody else got stuck on something similar.

Warren

System.TypeInitializationException was unhandled
  HResult=-2146233036
  Message=The type initializer for 'Couchbase.Configuration.Client.ClientConfiguration' threw an exception.
  Source=Couchbase.NetClient
  TypeName=Couchbase.Configuration.Client.ClientConfiguration
  StackTrace:
       at Couchbase.Configuration.Client.ClientConfiguration..ctor()
       at Couchbase.SslExample.Program.Main(String[] args) in C:\dev\couchbase-net-examples\Src\Couchbase.SslExample\Program.cs:line 17
       at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException: Common.Logging.ConfigurationException
       HResult=-2146232832
       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) in c:\_oss\common-logging\src\Common.Logging.Portable\Logging\Configuration\ArgUtils.cs:line 330
            at Common.Logging.Configuration.ArgUtils.Guard(Action action, String messageFormat, Object[] args) in c:\_oss\common-logging\src\Common.Logging.Portable\Logging\Configuration\ArgUtils.cs:line 290
            at Common.Logging.LogManager.BuildLoggerFactoryAdapter() in c:\_oss\common-logging\src\Common.Logging.Portable\Logging\LogManager.cs:line 470
            at Common.Logging.LogManager.get_Adapter() in c:\_oss\common-logging\src\Common.Logging.Portable\Logging\LogManager.cs:line 203
            at Common.Logging.LogManager.GetLogger[T]() in c:\_oss\common-logging\src\Common.Logging.Portable\Logging\LogManager.cs:line 400
            at Couchbase.Configuration.Client.ClientConfiguration..cctor()
       InnerException: System.Configuration.ConfigurationErrorsException
            HResult=-2146232062
            Message=An error occurred creating the configuration section handler for common/logging: Unable to create type 'Common.Logging.Log4Net.Log4NetLoggerFactoryAdapter, Common.Logging.Log4Net' (C:\dev\couchbase-net-examples\Src\Couchbase.SslExample\bin\Debug\Couchbase.SslExample.vshost.exe.Config line 15)
            Source=System.Configuration
            BareMessage=An error occurred creating the configuration section handler for common/logging: Unable to create type 'Common.Logging.Log4Net.Log4NetLoggerFactoryAdapter, Common.Logging.Log4Net'
            Filename=C:\dev\couchbase-net-examples\Src\Couchbase.SslExample\bin\Debug\Couchbase.SslExample.vshost.exe.Config
            Line=15
            StackTrace:
                 at System.Configuration.BaseConfigurationRecord.EvaluateOne(String[] keys, SectionInput input, Boolean isTrusted, FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentResult)
                 at System.Configuration.BaseConfigurationRecord.Evaluate(FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentResult, Boolean getLkg, Boolean getRuntimeObject, Object& result, Object& resultRuntimeObject)
                 at System.Configuration.BaseConfigurationRecord.GetSectionRecursive(String configKey, Boolean getLkg, Boolean checkPermission, Boolean getRuntimeObject, Boolean requestIsHere, Object& result, Object& resultRuntimeObject)
                 at System.Configuration.BaseConfigurationRecord.GetSectionRecursive(String configKey, Boolean getLkg, Boolean checkPermission, Boolean getRuntimeObject, Boolean requestIsHere, Object& result, Object& resultRuntimeObject)
                 at System.Configuration.BaseConfigurationRecord.GetSectionRecursive(String configKey, Boolean getLkg, Boolean checkPermission, Boolean getRuntimeObject, Boolean requestIsHere, Object& result, Object& resultRuntimeObject)
                 at System.Configuration.BaseConfigurationRecord.GetSection(String configKey)
                 at System.Configuration.ClientConfigurationSystem.System.Configuration.Internal.IInternalConfigSystem.GetSection(String sectionName)
                 at System.Configuration.ConfigurationManager.GetSection(String sectionName)
                 at Common.Logging.Configuration.DefaultConfigurationReader.GetSection(String sectionName) in c:\_oss\common-logging\src\Common.Logging.Portable\Logging\Configuration\DefaultConfigurationReader.cs:line 64
                 at Common.Logging.LogManager.<>c__DisplayClass6.<BuildLoggerFactoryAdapter>b__3() in c:\_oss\common-logging\src\Common.Logging.Portable\Logging\LogManager.cs:line 472
                 at Common.Logging.Configuration.ArgUtils.<>c__DisplayClass5.<Guard>b__4() in c:\_oss\common-logging\src\Common.Logging.Portable\Logging\Configuration\ArgUtils.cs:line 292
                 at Common.Logging.Configuration.ArgUtils.Guard[T](Function`1 function, String messageFormat, Object[] args) in c:\_oss\common-logging\src\Common.Logging.Portable\Logging\Configuration\ArgUtils.cs:line 318
            InnerException: Common.Logging.ConfigurationException
                 HResult=-2146232832
                 Message=Unable to create type 'Common.Logging.Log4Net.Log4NetLoggerFactoryAdapter, Common.Logging.Log4Net'
                 Source=Common.Logging
                 StackTrace:
                      at Common.Logging.ConfigurationSectionHandler.ReadConfiguration(XmlNode section) in c:\_oss\common-logging\src\Common.Logging\Logging\ConfigurationSectionHandler.cs:line 134
                      at Common.Logging.ConfigurationSectionHandler.Create(LogSetting parent, Object configContext, XmlNode section) in c:\_oss\common-logging\src\Common.Logging\Logging\ConfigurationSectionHandler.cs:line 204
                      at Common.Logging.ConfigurationSectionHandler.System.Configuration.IConfigurationSectionHandler.Create(Object parent, Object configContext, XmlNode section) in c:\_oss\common-logging\src\Common.Logging\Logging\ConfigurationSectionHandler.cs:line 226
                      at System.Configuration.RuntimeConfigurationRecord.RuntimeConfigurationFactory.CreateSectionImpl(RuntimeConfigurationRecord configRecord, FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentConfig, ConfigXmlReader reader)
                      at System.Configuration.RuntimeConfigurationRecord.RuntimeConfigurationFactory.CreateSectionWithRestrictedPermissions(RuntimeConfigurationRecord configRecord, FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentConfig, ConfigXmlReader reader)
                      at System.Configuration.RuntimeConfigurationRecord.CreateSection(Boolean inputIsTrusted, FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentConfig, ConfigXmlReader reader)
                      at System.Configuration.BaseConfigurationRecord.CallCreateSection(Boolean inputIsTrusted, FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentConfig, ConfigXmlReader reader, String filename, Int32 line)
                 InnerException: System.IO.FileNotFoundException
                      HResult=-2147024894
                      Message=Could not load file or assembly 'Common.Logging.Log4Net' or one of its dependencies. The system cannot find the file specified.
                      Source=mscorlib
                      FileName=Common.Logging.Log4Net
                      FusionLog==== Pre-bind state information ===
LOG: DisplayName = Common.Logging.Log4Net
 (Partial)
WRN: Partial binding information was supplied for an assembly:
WRN: Assembly Name: Common.Logging.Log4Net | Domain ID: 1
WRN: A partial bind occurs when only part of the assembly display name is provided.
WRN: This might result in the binder loading an incorrect assembly.
WRN: It is recommended to provide a fully specified textual identity for the assembly,
WRN: that consists of the simple name, version, culture, and public key token.
WRN: See whitepaper http://go.microsoft.com/fwlink/?LinkId=109270 for more information and common solutions to this issue.
LOG: Appbase = file:///C:/dev/couchbase-net-examples/Src/Couchbase.SslExample/bin/Debug/
LOG: Initial PrivatePath = NULL
Calling assembly : Common.Logging, Version=3.2.0.0, Culture=neutral, PublicKeyToken=af08829b84f0328e.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\dev\couchbase-net-examples\Src\Couchbase.SslExample\bin\Debug\Couchbase.SslExample.vshost.exe.Config
LOG: Using host configuration file: 
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).
LOG: Attempting download of new URL file:///C:/dev/couchbase-net-examples/Src/Couchbase.SslExample/bin/Debug/Common.Logging.Log4Net.DLL.
LOG: Attempting download of new URL file:///C:/dev/couchbase-net-examples/Src/Couchbase.SslExample/bin/Debug/Common.Logging.Log4Net/Common.Logging.Log4Net.DLL.
LOG: Attempting download of new URL file:///C:/dev/couchbase-net-examples/Src/Couchbase.SslExample/bin/Debug/Common.Logging.Log4Net.EXE.
LOG: Attempting download of new URL file:///C:/dev/couchbase-net-examples/Src/Couchbase.SslExample/bin/Debug/Common.Logging.Log4Net/Common.Logging.Log4Net.EXE.

                      StackTrace:
                           at System.RuntimeTypeHandle.GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMarkHandle stackMark, IntPtr pPrivHostBinder, Boolean loadTypeFromPartialName, ObjectHandleOnStack type)
                           at System.RuntimeTypeHandle.GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean loadTypeFromPartialName)
                           at System.RuntimeType.GetType(String typeName, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMark& stackMark)
                           at System.Type.GetType(String typeName, Boolean throwOnError, Boolean ignoreCase)
                           at Common.Logging.ConfigurationSectionHandler.ReadConfiguration(XmlNode section) in c:\_oss\common-logging\src\Common.Logging\Logging\ConfigurationSectionHandler.cs:line 129
                      InnerException:

#2

Hey thanks for the heads-up. I think Common.Logging has been a recurring problem in the .NET SDK and we’re looking at ways to deal with that.

Here’s a bug report that actually refers to problems with 3.1:

https://issues.couchbase.com/browse/NCBC-891

@jmorris might be able to add more.


#3

We’re trying the client out here and are not seeing this behavior.


#4

Are you trying it while using the demos from the .NET SDK Demos github repo, or with your own codebase? In my case I was using Couchbase.SslExample.


#5

Our own code. 2 different things. 1 was our code, and the other was my performance tester, shared elsewhere on these forums.


#6

Another thing, the documentation here is no longer valid:

http://docs.couchbase.com/developer/dotnet-2.1/setting-up-logging.html

In particular, the contents of the App.config shown there are no longer valid in the latest SDK, with the latest Common.Logging version.


#7

There is a ticket for this: https://issues.couchbase.com/browse/NCBC-861

-Jeff


#8

@Warren_Postma -

It looks like the work-around for this is to manually request the log4net dependency to be updated from 1.2.11 to 1.2.13 using NuGet:

Once you do this logging should work as expected.

-Jeff