C# 运行时出现应用程序配置文件错误
背景: 我有一个winform应用程序,由本地网络上的用户启动(路径:C# 运行时出现应用程序配置文件错误,c#,.net,winforms,app-config,C#,.net,Winforms,App Config,背景: 我有一个winform应用程序,由本地网络上的用户启动(路径:\\file-01\appsdeploy$\MyApp) 当我启动这个应用程序的时候,它运行得很好。但在其他一些计算机上,它不工作。我有一个例外: 为创建配置节处理程序时出错 MySection:请求失败 app.config文件中节的声明为: <configSections> <section name="MySection" type="MyGenerator.Config.MySection
\\file-01\appsdeploy$\MyApp
)
当我启动这个应用程序的时候,它运行得很好。但在其他一些计算机上,它不工作。我有一个例外:
为创建配置节处理程序时出错
MySection:请求失败
app.config文件中节的声明为:
<configSections>
<section name="MySection" type="MyGenerator.Config.MySection, MyGenerator"/>
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<section name="MySectionGenerator.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false"/>
</sectionGroup>
</configSections>
现在,本节:
<MySection>
<Addresses>
<add Name="1" Text="ADDRESS ONE"/>
<add Name="2" Text="ADDRESS TWO"/>
<add Name="3" Text="ADDRESS THREE"/>
<add Name="4" Text="ADDRESS FOUR"/>
<add Name="5" Text="ADDRESS FIVE"/>
<add Name="6" Text="ADDRESS SIX"/>
<add Name="7" Text="ADDRESS SEVEN"/>
</Addresses>
</MySection>
注意:如果我将可执行文件和配置文件复制到本地计算机上,它可以正常工作
你有什么想法、线索吗 使用allowExeDefinition=machinetoapplication选项进行检查。它可能与被“阻止”的exe有关,因为它是从网络驱动器运行的。正如这里所讨论的:仅适用于少数机器,而不是所有机器?可能机器和/或用户权限之间的一个或多个安全设置存在差异?没错!我不知道为什么,但当我将节addressConfigSection=ConfigurationManager.GetSection(“MySection”)替换为MySection时;通过var config=ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);MySection addressConfigSection=config.GetSection(“MySection”)作为MySection;