问题描述
今天,我经历了一个奇怪的问题,而试图远程调试建为.NET 4.0运行的应用程序。
应用程序驻留在网络共享和远程计算机执行。然而,应用程序崩溃,因为被许可的需求,在System.Configuration.ConfigurationManager.GetSection()方法,提出了一个SecurityException负载时各一次。我没有检查,如果在基类库其他权限需求也导致安全异常,但在所有的情况下,这不应该发生的新的CLR。
该应用程序在完全信任运行(选中它,而调试和往常一样这必须是在CLR 4.0 Intranet应用程序总是如此),所以我无言以对权限需求如何导致这种情况的一个例外。当建立针对3.5 SP1运行时(其中首次推出完全信任的网络共享的默认应用程序)万物运行正常。
我粘贴示例code以下。任何帮助是极大的AP preciated。
使用系统;
使用System.Configuration;
命名空间ConsoleApplication1
{
公共密封类AssetsSection:配置节
{
私人静态只读的ConfigurationProperty s_propPath;
私人静态只读ConfigurationPropertyCollection s_properties;
静态AssetsSection()
{
s_propPath =新的ConfigurationProperty(路径的typeof(字符串));
s_properties =新ConfigurationPropertyCollection()
{
s_propPath
};
}
公共静态AssetsSection获得()
{
返程(AssetsSection)ConfigurationManager.GetSection(测试/资产);
}
保护覆盖ConfigurationPropertyCollection属性
{
得到
{
返回s_properties;
}
}
公共字符串路径
{
得到
{
回报(字符串)基地[s_propPath]
}
组
{
基地[s_propPath] =值;
}
}
}
类节目
{
静态无效的主要(字串[] args)
{
Console.WriteLine(AssetsSection.Get()的路径。);
到Console.ReadLine();
}
}
}
和App.config文件;
< XML版本=1.0&GT?;
<结构>
< configSections>
< sectionGroup名称=测试>
<节名称=资产类型=ConsoleApplication1.AssetsSection,ConsoleApplication1/>
< / sectionGroup>
< / configSections>
<启动>
< supportedRuntime版本=4.0版的SKU =NETFramework,版本= V4.0,外形=客户/>
< /启动>
<试验>
<资产路径=.. \资产/>
< /试验>
< /结构>
先尝试加载配置和打开你的部分:
配置配置= ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
AssetsSection configSection =(AssetsSection)config.GetSection(测试/资产);
我碰到了与.NET 4中同样的问题,这对我的作品。
Today I experienced a weird problem while trying to remotely debug an application built for the .NET 4.0 runtime.
The application resides on a network share and executed by a remote machine. However the application crashes each time during load because of a SecurityException raised by a permission demand in the System.Configuration.ConfigurationManager.GetSection() method. I have not checked if other permission demands in the base class library also cause a security exception but in all cases this shouldn't be happening with the new CLR.
The application is running in full trust (checked it while debugging and as usual this must be always true for intranet applications in CLR 4.0) so I am clueless how a permission demand can cause an exception in this case. When built against the 3.5 SP1 runtime (which first introduced full trust for network shared apps by default) everythings runs as expected.
I pasted the sample code below. Any help is greatly appreciated.
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();
}
}
}
And the App.config file;
<?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>
Try loading the configuration first and open your section on that:
Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
AssetsSection configSection = (AssetsSection)config.GetSection("test/assets");
I ran into the same issue with .NET 4 and this works for me.
这篇关于网络共享.NET 4.0应用程序会导致SecurityException异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!