- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
首先,让我提前为这个超长的问题道歉——感谢所有坚持到最后的人!
我有一个 C#/.NET 3.5 类库,它没有安装在 GAC 中,因为该类库是另一个程序 (ArcMap.exe) 的插件。该程序实际上在启动时将 .dll 从存档中提取到用户的 Local Settings\Application Data 文件夹下的文件夹中,但我能够在运行时使用 this.GetType().Assembly.Location
获取它的位置。 .
在图书馆我有一个类叫做CustomConfigSection
在 .config 文件中引用。
该库有一个带有方法的类 LoadConfigSection()
使用 ConfigurationManager.OpenMappedExeConfiguration()
从 .config 文件(存储在用户的应用程序数据文件夹中)读取并返回 CustomConfigSection
——或者它应该。会发生什么 GetSection()
抛出一个讨厌的ConfigurationErrorsException
说找不到包含我的 CustomConfigSection
的程序集.
令人恼火的是这两天前还在工作。我认为 Windows 更新打破了这一点。我回去尝试了我知道工作正常的以前版本的代码,但无济于事。环境发生了变化,不是我的代码发生了变化,而是现在其他机器上也发生了变化,所以不仅仅是我!
这是一个示例 .config 文件:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="customConfigSection" type="TestExeConfigurationFileMapAddin.CustomConfigSection, TestExeConfigurationFileMapAddin, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
</configSections>
<customConfigSection>
<customConfigCollection>
<customConfig name="asdf" />
<customConfig name="1234" />
<customConfig name="jlkjjkljj" />
</customConfigCollection>
</customConfigSection>
</configuration>
我用来阅读它的代码(正如我在 2 天前提到的那样运行良好):
private CustomConfigSection LoadConfigSection()
{
ExeConfigurationFileMap configFileMap = new ExeConfigurationFileMap();
configFileMap.ExeConfigFilename = m_userConfigFilePath;
Configuration config = ConfigurationManager.OpenMappedExeConfiguration(configFileMap, ConfigurationUserLevel.None);
CustomConfigSection configSection = config.GetSection("customConfigSection") as CustomConfigSection;
return configSection;
}
m_userConfigFilePath
是 .config 文件的有效路径,Configuration
对象的 HasFile
属性为真。
这是我在启用 Fusion 后得到的错误程序集绑定(bind)日志记录:
System.Configuration.ConfigurationErrorsException: An error occurred creating the configuration section handler for customConfigSection: Could not load file or assembly 'TestExeConfigurationFileMapAddin, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified. (C:\Documents and Settings\...\Application Data\TestExeConfigurationFileMapAddin\test.config line 4) ---> System.IO.FileNotFoundException: Could not load file or assembly 'TestExeConfigurationFileMapAddin, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.
File name: 'TestExeConfigurationFileMapAddin, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'
at System.Configuration.TypeUtil.GetTypeWithReflectionPermission(IInternalConfigHost host, String typeString, Boolean throwOnError)
at System.Configuration.MgmtConfigurationRecord.CreateSectionFactory(FactoryRecord factoryRecord)
at System.Configuration.BaseConfigurationRecord.FindAndEnsureFactoryRecord(String configKey, Boolean& isRootDeclaredHere)
Assembly manager loaded from: C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\mscorwks.dll
Running under executable C:\Program Files\ArcGIS\Desktop10.0\Bin\ArcMap.exe
--- A detailed error log follows.
=== Pre-bind state information ===
LOG: User = ...
LOG: DisplayName = TestExeConfigurationFileMapAddin, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
(Fully-specified)
LOG: Appbase = file:///C:/Program Files/ArcGIS/Desktop10.0/Bin/
LOG: Initial PrivatePath = NULL
Calling assembly : System.Configuration, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\Program Files\ArcGIS\Desktop10.0\Bin\ArcMap.exe.Config
LOG: Using machine configuration file from C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\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:/Program Files/ArcGIS/Desktop10.0/Bin/TestExeConfigurationFileMapAddin.DLL.
LOG: Attempting download of new URL file:///C:/Program Files/ArcGIS/Desktop10.0/Bin/TestExeConfigurationFileMapAddin/TestExeConfigurationFileMapAddin.DLL.
LOG: Attempting download of new URL file:///C:/Program Files/ArcGIS/Desktop10.0/Bin/TestExeConfigurationFileMapAddin.EXE.
LOG: Attempting download of new URL file:///C:/Program Files/ArcGIS/Desktop10.0/Bin/TestExeConfigurationFileMapAddin/TestExeConfigurationFileMapAddin.EXE.
--- End of inner exception stack trace ---
at System.Configuration.BaseConfigurationRecord.FindAndEnsureFactoryRecord(String configKey, Boolean& isRootDeclaredHere)
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, Boolean getLkg, Boolean checkPermission)
at System.Configuration.Configuration.GetSection(String sectionName)
at TestExeConfigurationFileMapAddin.Form1.LoadConfigSection() in C:\CSProjects\TestExeConfigurationFileMapAddin\TestExeConfigurationFileMapAddin\Form1.cs:line 46
at TestExeConfigurationFileMapAddin.Form1.LoadConfig() in C:\CSProjects\TestExeConfigurationFileMapAddin\TestExeConfigurationFileMapAddin\Form1.cs:line 28
并且 Fusion 失败的绑定(bind)日志本身:
*** Assembly Binder Log Entry (7/29/2011 @ 12:46:02 PM) ***
The operation failed.
Bind result: hr = 0x80070002. The system cannot find the file specified.
Assembly manager loaded from: C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\mscorwks.dll
Running under executable C:\Program Files\ArcGIS\Desktop10.0\Bin\ArcMap.exe
--- A detailed error log follows.
=== Pre-bind state information ===
LOG: User = ...
LOG: DisplayName = TestExeConfigurationFileMapAddin, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
(Fully-specified)
LOG: Appbase = file:///C:/Program Files/ArcGIS/Desktop10.0/Bin/
LOG: Initial PrivatePath = NULL
LOG: Dynamic Base = NULL
LOG: Cache Base = NULL
LOG: AppName = NULL
Calling assembly : System.Configuration, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\Program Files\ArcGIS\Desktop10.0\Bin\ArcMap.exe.Config
LOG: Using machine configuration file from C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\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:/Program Files/ArcGIS/Desktop10.0/Bin/TestExeConfigurationFileMapAddin.DLL.
LOG: Attempting download of new URL file:///C:/Program Files/ArcGIS/Desktop10.0/Bin/TestExeConfigurationFileMapAddin/TestExeConfigurationFileMapAddin.DLL.
LOG: Attempting download of new URL file:///C:/Program Files/ArcGIS/Desktop10.0/Bin/TestExeConfigurationFileMapAddin.EXE.
LOG: Attempting download of new URL file:///C:/Program Files/ArcGIS/Desktop10.0/Bin/TestExeConfigurationFileMapAddin/TestExeConfigurationFileMapAddin.EXE.
LOG: All probing URLs attempted and failed.
显然 ConfigurationManager
正在寻找包含我的 CustomConfigSection
的程序集从错误的位置——至于为什么这只是最近才开始发生我不知道,但我确实在 2-3 天前安装了一堆 Windows 更新。我正在运行 32 位 Windows XP Pro SP3。
在不完全理解所有这些术语的含义的情况下,Fusion 日志给了我希望,我可以更改加载上下文或策略以强制它从正确的位置加载程序集。这是真的吗?如果是,怎么会这样?
最佳答案
使用 Assembly.LoadFrom()
和处理 AssemblyResolve
事件是关键——this answer 中的代码示例为我解决了这个问题。我很想听听任何专家对其工作原理的看法。
关于c# - ConfigurationManager.OpenMappedExeConfiguration.GetSection() 失败(最近才开始发生),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6878194/
我正在尝试创建一个基于 AppSettings 的自定义配置文件部分: 当我尝试通过 ConfigurationManager.GetSection("customConfiguration
这是ConfigurationSection类 using System.Configuration; namespace CampusWebStore.Config { public cla
我无法让我的 Configuration.GetSection 返回 .Value 中的数据。我想我已经实现了这个 question 中的所有建议,但仍然无法正常工作。 应用设置.json {
你好,我在 .NET Core 应用程序 中使用了一个 json 配置文件,我不明白为什么我为对象的子部分获取了 null 值: { "tt": { "aa":3,
我卡住了!这看起来真的很愚蠢,但我看不出我哪里错了。我正在创建一个 2.0 C# ASP.NET 网站。我正在尝试使用 web.config 文件中的自定义部分: DatabaseFactorySec
我正在尝试在我的应用程序中检索配置。 我已将 IConfiguration 传递给需要提取一些设置的服务类。 这个类看起来有点像这样: private IConfiguration _configur
这真让我吃惊。我正在使用 Configuration.GetSection 从 appsettings.json 读取值方法,简而言之,我的 appsettings.json 如下所示: "AppSe
这是我的 app.config 但是当我在代码中调用它时,我得到一个空值 public void
首先,让我提前为这个超长的问题道歉——感谢所有坚持到最后的人! 我有一个 C#/.NET 3.5 类库,它没有安装在 GAC 中,因为该类库是另一个程序 (ArcMap.exe) 的插件。该程序实际上
我创建了一个使用 FastScroll 的 ListView。 (见图片)当用户单击以下任何按钮(即所有轨道、艺术家、专辑)时,每次调用以下自定义 ArrayAdater ArrayAdapter a
我正在尝试学习如何使用 ConfigurationSection 类。我曾经使用 IConfigurationSectionHandler 但发布它已被折旧。所以作为一个好 child ,我正在尝试“
我有一个单元测试项目,它有自己的 app.config 文件,它是对被测试的目标项目定义的真实配置文件的模拟。这个模拟文件由单元测试代码(而不是目标项目)加载和处理,如果我只在这个测试项目中运行测试,
好的,所以...... var test = ConfigurationManager.GetSection("test"); 到目前为止一切顺利。调试器显示 test 包含一个键 fo
客观的 使用 Moq 和 XUnit 创建一个模拟对象,用于加载特定部分“字符/技能”以增强单元测试的覆盖率。 SUT(在某些时候)以这种方式加载设置 var skills = Configurati
我正在编写一个类库,它在其 app.config 中有设置,最终将被少数其他 .NET 应用程序调用。为了从中获取设置,我正在使用 ConfigurationManager.GetSection,如下
每次调用 Configuration.GetSection 时,返回对象的 Value 属性始终为 null。 我的启动构造函数 public Startup(IHostingEnvironment
我的app.config文件如下: 我有以下(单独的)类来获取配置: na
本文整理了Java中org.springframework.extensions.config.xml.XMLConfigService.getSections()方法的一些代码示例,展示了XMLCo
我正在尝试使用 HostBuilder在 MsTest 中上课测试用例如下: [TestMethod] public void SomeTest()
具有复杂(对象列表)配置类型的 Azure 函数正在本地工作(在 local.settings.json 中使用该复杂类型),但无法在 Azure 中读取/创建对象列表(在 Azure 函数配置中使用
我是一名优秀的程序员,十分优秀!