0

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).

RJN
  • 696
  • 8
  • 17
  • 1
    I normally diagnose these kind of errors by enabling fusion logging and then check the logs https://learn.microsoft.com/en-us/dotnet/framework/tools/fuslogvw-exe-assembly-binding-log-viewer to see where it actually tries to load / probe those assemblies from. – rene Jul 17 '18 at 07:31
  • @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 Jul 19 '18 at 05:33
  • 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 Jul 19 '18 at 06:54
  • I see the enterprise logging DLL is referred from: ..\\packages\EnterpriseLibrary.Logging.6.0.1304.0\lib\NET45\Microsoft.Practices.EnterpriseLibrary.Logging.dll and also Microsoft.Practices.EnterpriseLibrary.Common.dll – RJN Jul 19 '18 at 07:14
  • Please go over https://stackoverflow.com/questions/255669/how-to-enable-assembly-bind-failure-logging-fusion-in-net as the info you provide is not enough to diagnose. If you still can't find which file won't load from which path install [System Monitior](https://learn.microsoft.com/en-us/sysinternals/downloads/procmon) and filter on File failures. It should show the files (and their paths) it can't query/open. Remember to run those tools elevated (right click -> Run as Administrator) – rene Jul 19 '18 at 07:33
  • @rene I see the fusion logger says, LOG: No application configuration file found. What is this mean? I have app.config but why it says so?. Is this because I have copy pasted that into C# dll project, it doesn't understand that? PS: See the complete log message added with the question. – RJN Jul 19 '18 at 13:08
  • 2
    I think this answer from Hans is relevant: https://stackoverflow.com/a/35456786/578411 – rene Jul 19 '18 at 13:15
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/176339/discussion-between-rjn-and-rene). – RJN Jul 19 '18 at 13:40

1 Answers1

0

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.

RJN
  • 696
  • 8
  • 17