简体   繁体   English

无法加载文件或程序集'Microsoft.Practices.EnterpriseLibrary.Logging

[英]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. 我有启用了COM-Interop的C#库(DLL),在其中配置了App.config以启用企业日志记录。 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) 但是,一旦从COM dll调用了BootStrapper.Run,​​尽管我的bin文件夹Microsoft.Practices.EnterpriseLibrary.Logging.dll(v6.0.1304.0)Microsoft.Practices中存在日志记录和常见的DLL,但我仍然收到以下错误消息。 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. {“在创建用于loggingConfiguration的配置节处理程序时发生错误:无法加载文件或程序集'Microsoft.Practices.EnterpriseLibrary.Logging,Version = 6.0.0.0,Culture = neutral,PublicKeyToken = 31bf3856ad364e35'或其依赖项之一。系统找不到指定的文件。

NOTE : If I call BootStrapper.Run() from console (EXE) application, the logger facade initialization is success. 注意 :如果我从控制台(EXE)应用程序调用BootStrapper.Run(),则记录器外观初始化成功。 But when I call the same from COM-Interop enabled C# DLL, I get the above error. 但是,当我从启用COM-Interop的C#DLL中调用相同代码时,出现上述错误。

I get the mentioned exception when trying to initialize LogWriterFactory (3rd line in try block) 我在尝试初始化LogWriterFactory时遇到了提到的异常(try块中的第三行)

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: 运行Fusion logger后,我得到以下日志:

=== 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 | 日志:DisplayName = Microsoft.Practices.EnterpriseLibrary.Logging,文化=中性,PublicKeyToken = 31bf3856ad364e35(部分)WRN:为程序集提供了部分绑定信息:WRN:程序集名称: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. 域ID:1 WRN:当仅提供部分程序集显示名称时,将发生部分绑定。 WRN: This might result in the binder loading an incorrect assembly. WRN:这可能导致活页夹加载不正确的组件。 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:建议为程序集提供完全指定的文本标识,WRN:由简单名称,版本,区域性和公共密钥令牌组成。

=== LOG: This bind starts in default load context. === LOG:此绑定在默认加载上下文中启动。 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. 日志:使用主机配置文件:日志:使用来自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: 使用Fusion日志查看器,我发现存在一些问题:

1) My App.config file missing version info for enterprise logging dll in header(app.config). 1)我的App.config文件缺少标头(app.config)中企业日志记录dll的版本信息。 After adding version info, error message has gone. 添加版本信息后,错误消息消失了。

2) Then, I faced DLL hell problem. 2)然后,我遇到了DLL地狱问题。 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. 由于无法启动日志记录DLL,COM DLL从GAC和EXE位置(但不在程序集位置)开始寻找其依赖项。

I choose to copy enterprise Library logging DLLs into EXE and fixed the issue. 我选择将企业库记录DLL复制到EXE并解决了该问题。

Thanks much @rene and @Hans who really helped me here. 非常感谢@rene和@Hans,他们在这里确实为我提供了帮助。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 C#无法加载文件或程序集'Microsoft.Practices.EnterpriseLibrary.Logging - C# Could not load file or assembly 'Microsoft.Practices.EnterpriseLibrary.Logging 无法加载文件或程序集Microsoft.Practices.EnterpriseLibrary.Configuration - Could not load file or assembly Microsoft.Practices.EnterpriseLibrary.Configuration “无法加载文件或程序集'Microsoft.Practices.EnterpriseLibrary.Validation”异常 - “Could not load file or assembly 'Microsoft.Practices.EnterpriseLibrary.Validation” exception 无法加载文件或程序集'Microsoft.Practices.EnterpriseLibrary.Caching - Could not load file or assembly 'Microsoft.Practices.EnterpriseLibrary.Caching 无法在WCF中加载文件或程序集'Microsoft.Practices.EnterpriseLibrary.Common - Could not load file or assembly 'Microsoft.Practices.EnterpriseLibrary.Common in WCF C#Microsoft.Practices.EnterpriseLibrary.Logging错误 - C# Microsoft.Practices.EnterpriseLibrary.Logging error 无法加载文件或程序集“Microsoft.Practices.EnterpriseLibrary.Common”或其依赖项之一 - Could not load file or assembly 'Microsoft.Practices.EnterpriseLibrary.Common' or one of its dependencies 无法加载文件或程序集“Microsoft.Practices.EnterpriseLibrary.Common,Version=6.0.0.0,Culture=neutral,PublicKeyToken=31bf3856ad364e35”或 - Could not load file or assembly 'Microsoft.Practices.EnterpriseLibrary.Common, Version=6.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or 无法加载文件或程序集 Microsoft.Practices.ServiceLocation,版本 = 1.3.0.0 - Could not load file or assembly Microsoft.Practices.ServiceLocation, Version=1.3.0.0 无法加载文件或程序集“Microsoft.Practices.Unity” - Could not load file or assembly 'Microsoft.Practices.Unity'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM