0
votes

I have COM-Interop enabled C# library (DLL) where I configured App.config to enable enterprise logging. But as soon as my BootStrapper.Run is called from COM dll, I keep getting the below error though logging & common DLLs exist in my bin folder Microsoft.Practices.EnterpriseLibrary.Logging.dll (v6.0.1304.0) Microsoft.Practices.EnterpriseLibrary.Common.dll (v6.0.1304.0)

{"An error occurred creating the configuration section handler for loggingConfiguration: Could not load file or assembly 'Microsoft.Practices.EnterpriseLibrary.Logging, Version=6.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.

NOTE: If I call BootStrapper.Run() from console (EXE) application, the logger facade initialization is success. But when I call the same from COM-Interop enabled C# DLL, I get the above error.

I get the mentioned exception when trying to initialize LogWriterFactory (3rd line in try block)

public LoggingService()
{
        try
        {
            var appConfig = ConfigurationManager.OpenExeConfiguration(Assembly.GetExecutingAssembly().Location);
            IConfigurationSource configurationSource = new FileConfigurationSource(appConfig.FilePath);
            var logWriterFactory = new LogWriterFactory(configurationSource);
            Logger.SetLogWriter(logWriterFactory.Create());
        }
        catch(Exception exception)
        {
            Console.Write(exception.Message);  
        }
}

Am I missing something here?

After running fusion logger I get the below log:

=== Pre-bind state information ===

LOG: DisplayName = Microsoft.Practices.EnterpriseLibrary.Logging, Culture=neutral, PublicKeyToken=31bf3856ad364e35 (Partial) WRN: Partial binding information was supplied for an assembly: WRN: Assembly Name: Microsoft.Practices.EnterpriseLibrary.Logging, Culture=neutral, PublicKeyToken=31bf3856ad364e35 | 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.

=== LOG: This bind starts in default load context. LOG: No application configuration file found. 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).

1
I normally diagnose these kind of errors by enabling fusion logging and then check the logs docs.microsoft.com/en-us/dotnet/framework/tools/… to see where it actually tries to load / probe those assemblies from. - rene
@rene I got the below log message for Fusion log: FusionLog = "=== Pre-bind state information ===\r\nLOG: DisplayName = Microsoft.Practices.EnterpriseLibrary.Logging, Culture=neutral, PublicKeyToken=31bf3856ad364e35\n (Partial)\r\nWRN: Partial binding information was supplied for an assembly:\r\nWRN: Assembly Name: Mi... - RJN
There is a whole bunch of paths in there that it should have probed. Are the folders you see there as you would expect? As in, one of those folders contain the dll's from your app? - rene
I see the enterprise logging DLL is referred from: ..\<Project>\packages\EnterpriseLibrary.Logging.6.0.1304.0\lib\NET45\Microsoft.Practices.EnterpriseLibrary.Logging.dll and also Microsoft.Practices.EnterpriseLibrary.Common.dll - RJN
I think this answer from Hans is relevant: stackoverflow.com/a/35456786/578411 - rene

1 Answers

0
votes

Using Fusion log viewer, I found there are some issue:

1) My App.config file missing version info for enterprise logging dll in header(app.config). After adding version info, error message has gone.

2) Then, I faced DLL hell problem. COM DLL start looking for its dependencies from GAC and EXE location (but not on assembly location) due to which it was unable to launch the logging DLL.

I choose to copy enterprise Library logging DLLs into EXE and fixed the issue.

Thanks much @rene and @Hans who really helped me here.