Dav*_*vid 10 .net c# clr securityexception .net-4.0
今天,我在尝试远程调试为.NET 4.0运行时构建的应用程序时遇到了一个奇怪的问题.
应用程序驻留在网络共享上并由远程计算机执行.但是,由于System.Configuration.ConfigurationManager.GetSection()方法中的权限要求引发了SecurityException,因此应用程序在加载期间每次都会崩溃.我没有检查基类库中的其他权限要求是否也会导致安全性异常,但在所有情况下都不应该使用新的CLR.
应用程序以完全信任的方式运行(在调试时检查它,并且像往常一样,对于CLR 4.0中的Intranet应用程序必须始终如此)所以我很无能在这种情况下权限需求如何导致异常.当针对3.5 SP1运行时(默认情况下首次引入对网络共享应用程序的完全信任)构建时,每个运行都按预期运行.
我粘贴了下面的示例代码.任何帮助是极大的赞赏.
using System;
using System.Configuration;
namespace ConsoleApplication1
{
public sealed class AssetsSection : ConfigurationSection
{
private static readonly ConfigurationProperty s_propPath;
private static readonly ConfigurationPropertyCollection s_properties;
static AssetsSection()
{
s_propPath = new ConfigurationProperty("path", typeof(String));
s_properties = new ConfigurationPropertyCollection()
{
s_propPath
};
}
public static AssetsSection Get()
{
return (AssetsSection) ConfigurationManager.GetSection("test/assets");
}
protected override ConfigurationPropertyCollection Properties
{
get
{
return s_properties;
}
}
public String Path
{
get
{
return (String) base[s_propPath];
}
set
{
base[s_propPath] = value;
}
}
}
class Program
{
static void Main(String[] args)
{
Console.WriteLine(AssetsSection.Get().Path);
Console.ReadLine();
}
}
}
Run Code Online (Sandbox Code Playgroud)
和App.config文件;
<?xml version="1.0"?>
<configuration>
<configSections>
<sectionGroup name="test">
<section name="assets" type="ConsoleApplication1.AssetsSection, ConsoleApplication1"/>
</sectionGroup>
</configSections>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0,Profile=Client"/>
</startup>
<test>
<assets path="..\Assets"/>
</test>
</configuration>
Run Code Online (Sandbox Code Playgroud)
小智 17
尝试首先加载配置并打开您的部分:
Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
AssetsSection configSection = (AssetsSection)config.GetSection("test/assets");
Run Code Online (Sandbox Code Playgroud)
我遇到了与.NET 4相同的问题,这对我有用.
| 归档时间: |
|
| 查看次数: |
5228 次 |
| 最近记录: |