标签: configurationmanager

如何指示NUnit从特定目录加载程序集的dll.config文件?

如果程序集包含app.config文件,ConfigurationManager只要它与通过NUnit-Gui执行的NUnit项目位于同一目录中,就会加载它.为了说明考虑以下文件夹结构.

+ TestFolder
    testProject.nunit
  + AssemblyAFolder
      assemblyA.dll
      assemblyA.dll.config
  + AssemblyBFolder
      assemblyB.dll
      assemblyB.dll.config
Run Code Online (Sandbox Code Playgroud)

两者AssemblyAAssemblyB锻炼代码调用ConfigurationManager.如果我在NUnit-Gui中独立运行这些测试程序集,ConfigurationManager将正确解析本地配置文件.

然而,如果我加载testProject.nunit到NUnit的桂(其包含两者的引用AssemblyAAssemblyB),ConfigurationManager查找在配置文件TestFolder而不管哪个组件当前正在执行.

有没有办法指示NUnit将应用程序配置重新加载到当前程序集目录中的应用程序配置?

以下是内容testProject.nunit:

<NUnitProject>
  <Settings activeconfig="Debug" />
  <Config name="Debug" binpathtype="Auto">
    <assembly path="AssemblyAFolder\assemblyA.dll" />
    <assembly path="AssemblyBFolder\assemblyB.dll" />
  </Config>
</NUnitProject>
Run Code Online (Sandbox Code Playgroud)

.net nunit unit-testing configurationmanager app-config

13
推荐指数
2
解决办法
1万
查看次数

System.Web.Configuration.WebConfigurationManager和System.Configuration.ConfigurationManager之间的行为差​​异

我在使用ASP.NET网站的测试服务器上遇到了一些麻烦.我搞砸了,并且默认网站的主目录指向了错误的位置.当我尝试:

ConfigurationManager.ConnectionStrings["connectionString"]; 
Run Code Online (Sandbox Code Playgroud)

它返回null,但是

using System.Web.Configuration;

/* ... */

var rootWebConfig =
    WebConfigurationManager.OpenWebConfiguration(Request.ApplicationPath);

WebConfigurationManager.OpenWebConfiguration(Request.ApplicationPath);

rootWebConfig.ConnectionStrings.ConnectionStrings["connectionString"].ConnectionString;` 
Run Code Online (Sandbox Code Playgroud)

返回正确的连接字符串.

这两种方法之间有什么区别?

编辑:我真正要问的是,为什么ConfigurationManager在主目录设置不正确时方法失败,否则成功,并且WebConfigurationManager无论主目录是否正确设置都成功?是否存在其他差异,例如关于访问控制的假设?

c# asp.net configurationmanager behavior webconfigurationmanager

12
推荐指数
1
解决办法
1万
查看次数

在类库中找不到ConfigurationManager

所以,我有一个我知道会被网站使用的类库,我需要访问配置设置.我添加了对System.Configuration的引用,但我在类库中找不到ConfigurationManager.一些事情,一个是当我添加对System.Configuration的引用时,它显示为带有小写'c'的"System.configuration",我认为这很奇怪.另一件事,当我访问System.Configuration时,最接近ConfigurationManager的是"ConfigurationSettings".我在Web应用程序中查看了引用的属性,该应用程序允许我使用ConfigurationManager和此类库,它们都指向完全相同的文件.我需要以另一种方式做到这一点吗?

这是我对它的参考SS:

在此输入图像描述

.net c# configurationmanager class-library web-config

12
推荐指数
2
解决办法
2万
查看次数

如何将应用程序设置加载到NHibernate.Cfg.Configuration对象?

如何NHibernate.Cfg.Configuration使用System.Configuration.ConfigurationManagerApp.config 将应用程序设置加载到对象?

nhibernate configurationmanager app-config

11
推荐指数
2
解决办法
3万
查看次数

如何通过ConfigurationManager写入User.Config文件?

我正在尝试使用ConfigurationManager将用户设置保留到配置文件中.

我想将这些设置仅限于用户,因为没有管理员权限,无法在Vista/Win 7上保存应用程序更改.

这似乎得到了用户的配置,它似乎保存在Win 7中([Drive]:\ Users\[Username]\AppData\Local\[ApplicationName]\[AssemblyName] [hash]\[Version \]

Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.PerUserRoamingAndLocal);
Run Code Online (Sandbox Code Playgroud)

每当我尝试将任何更改保存到此配置时,我都会遇到以下异常:

InnerException: System.InvalidOperationException
Message="ConfigurationSection properties cannot be edited when locked."
Source="System.Configuration"
StackTrace:
    at System.Configuration.SectionInformation.VerifyIsEditable()
    at System.Configuration.MgmtConfigurationRecord.GetConfigDefinitionUpdates(Boolean requireUpdates, ConfigurationSaveMode saveMode, Boolean forceSaveAll, ConfigDefinitionUpdates& definitionUpdates, ArrayList& configSourceUpdates)
Run Code Online (Sandbox Code Playgroud)

我尝试将自定义ConfigurationSection添加到此配置中.我已经尝试添加到AppSettingsSection.每当我调用config.Save()它时抛出上面的异常.

有任何想法吗?

我尝试通过Project-> Settings设计器使用ApplicationSettingsBase类,但似乎不能保存自定义类型.我想要类似的功能,能够保存自定义类型.

.net c# settings configurationmanager configuration-files

11
推荐指数
1
解决办法
1万
查看次数

如何在ASP.NET Web应用程序中打开SectionGroup?

我有一个小的ASP.NET Web应用程序托管在集成测试中(在NUnit中执行).我的产品代码通常可以从web.config或app.config文件中找到配置数据,但出于某种原因,在托管ASP.NET时,我似乎ArgumentException在执行第一个命令时得到了:

var configuration = ConfigurationManager.OpenExeConfiguration(null);
return configuration.GetSectionGroup(SectionGroupName);
Run Code Online (Sandbox Code Playgroud)

不在独立的exe内部运行时必须指定exePath.

我不知道该把什么放在这里.我的产品没有一个合理的exePath作为参数传递给这个方法,因为它通常在Web服务器中运行.此外,通常可以使用以下方式打开普通Sections(而不是SectionGroups):

ConfigurationManager.GetSection(SectionName)
Run Code Online (Sandbox Code Playgroud)

即使在单元测试中,这也适用于App.config文件以某种方式神奇地被读取.这是我在阅读SectionGroups时想要的.

有任何想法吗?

asp.net configurationmanager

11
推荐指数
3
解决办法
8818
查看次数

我的Configuration Manager中没有"任何CPU"选项

我在VS2010(或之前)中读过几篇关于配置管理器的帖子,但我找不到我的问题.

我有一个包含6个项目的解决方案.当我打开配置管理器时,我可以选择:"Active Solution Configuration",其值为Debug,Release,New或Edit.ÁctiveSolutionPlatform'具有值任何CPU,混合平台,x64,x86,新建或编辑.对于我的6个项目中的任何一个,配置(调试,发布,新建,编辑),平台(非启动项目:任何CPU,新建,编辑和启动项目:x64,新建,编辑).

对于除启动项目以外的所有项目,Platform的唯一(实际)选择是"任何CPU",我认为这很好.

但是,对于启动项目我只能选择x64,所以我假设在32位Windows操作系统上运行它会有问题吗?

我在历史上玩了一些价值观,现在有人把这个错误邮寄给我:

此文件的版本与您正在运行的Windows版本不兼容.检查您的计算机系统信息,以查看是否需要该程序的x86(32位)或x64(64位)版本,然后与软件发行商联系

(当我选择x86平台时,我只能在我的启动项目中选择x64作为平台,而其他人则设置为'任何CPU'.

当尝试将任何CPU添加到启动项目时,我可以选择它,但它要求复制设置,我只能选择x64或为空.选择其中任何一个都会导致错误:

无法创建此平台,因为已存在同名的解决方案平台.

我假设它以前设置为x86,但我不确定,无论如何,我怎样才能为我的启动项目获得"任何CPU"选择?

更新:突然之间,我可以添加选项"任何CPU"而不会出现错误.所以我的问题解决了......

我只是不知道为什么它第一次没有工作......我只是关闭窗口并重新启动它,这是可能的.

c# configurationmanager visual-studio-2010 anycpu

11
推荐指数
2
解决办法
2万
查看次数

为什么我在App.config中对AppSettings的更改在运行时没有考虑到?(控制台应用)

我有一个控制台应用程序,它有自己的App.config.

我需要不时更改部分值.

我的问题是,当我在bin/debug文件夹中执行exe时,它会正确获取相关的appsettings.但是当我编辑和更改某些键/值对的值并重新运行exe时,它仍然会读取原始值.

(通过RE-RUN我的意思是通过调用MyTool.exe在命令promt上运行应用程序)

我试着打电话

ConfigurationManager.RefreshSection("appSettings");
Run Code Online (Sandbox Code Playgroud)

在我的主要方法的开头.但没有帮助.

你能给些建议么?谢谢

.net c# configurationmanager app-config

11
推荐指数
1
解决办法
3万
查看次数

无法获取我的自定义配置部分

我正在尝试创建一个自定义配置部分来加载我的应用程序监视器的"烤箱"列表.这是我第一次使用配置部分,我尝试按照示例进行操作; 但是,我无法弄清楚我错过了什么.

当我尝试获取配置部分时,我得到以下异常:

为BurnIn创建配置节处理程序时出错:无法从程序集'System.Configuration,Version = 4.0.0.0,Culture = neutral,PublicKeyToken = b03f5f7f11d50a3a'加载类型'BurnIn.UI.BurnInConfigurationSection'.(C:\ MKS\BurnIn\PC_SW\bin\BurnIn.UI.vshost.exe.config第8行)

在我的主要内容中我尝试过:System.Configuration.Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); if(config.Sections [BurnInSection] == null)...

BurnInConfigurationSection burnInConfigSection = config.GetSection(BurnInSection) as BurnInConfigurationSection; 

BurnInConfigurationSection burnInConfigSection = ConfigurationManager.GetSection(BurnInSection) as BurnInConfigurationSection;
Run Code Online (Sandbox Code Playgroud)

一切似乎都会导致同样的例外

当我查看config.FilePath时,我已验证的"C:\ MKS\BurnIn\PC_SW\bin\BurnIn.UI.vshost.exe.config"与app.config文件匹配.

这是我的配置类:

namespace BurnIn.UI
{
/// <summary>
/// BurnIn Application configuration section in app.config
/// </summary>
public class BurnInConfigurationSection : ConfigurationSection
{
    [ConfigurationProperty("Ovens", IsDefaultCollection = false)]
    [ConfigurationCollection(typeof(OvenCollection),
        AddItemName = "add",
        ClearItemsName = "clear",
        RemoveItemName = "remove")]
    public OvenCollection Ovens
    {
        get { return (OvenCollection)base["Ovens"]; }
        set { …
Run Code Online (Sandbox Code Playgroud)

.net c# configurationmanager app-config

11
推荐指数
1
解决办法
2万
查看次数

dll.config没有复制到临时的asp.net文件夹中

我有一个Web.Api应用程序,它使用来自不同程序集的函数.对于这个程序集,我创建了一个.config文件,我存储了一些字符串.

我使用以下代码来获取其中一个字符串:

private static string LogUrl = ConfigurationManager.OpenExeConfiguration(Assembly.GetExecutingAssembly().Location).AppSettings.Settings["WebApi-LogUrl"].Value.ToString();
Run Code Online (Sandbox Code Playgroud)

Assembly.GetExecutingAssembly().Location指向临时的asp.net文件,(C:\ Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files\root\dc2fa3d4\834ee436\assembly\dl3\cd068512)但我的dll.config文件不是在那里复制.结果是我无法调试我的应用程序,并且在真正的IIS服务器上运行代码时它也给出了null.

如果我在获取设置之前设置了一个断点,我可以抓住临时文件夹,当我复制我的dll.config文件时,一切正常,但我应该如何自动完成.

我将我的dll.config文件的属性设置为"构建操作:内容","复制到输出目录:始终"

任何帮助将不胜感激,现在谷歌搜索了几个小时.:(

最诚挚的问候,Peter Larsson!

asp.net configurationmanager

11
推荐指数
1
解决办法
2814
查看次数