简体   繁体   中英

Could not load file or assembly 'Microsoft.Practices.EnterpriseLibrary.Logging

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM