- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
今天,我在尝试远程调试为 .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();
}
}
}
和 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>
最佳答案
首先尝试加载配置并打开您的部分:
Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
AssetsSection configSection = (AssetsSection)config.GetSection("test/assets");
我遇到了与 .NET 4 相同的问题,这对我有用。
关于c# - 网络共享上的 .NET 4.0 应用程序导致 SecurityException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2725432/
我正在编写一个 C# 程序(具体来说是一个 IRC 机器人)并使用脚本库 Jint ( http://jint.codeplex.com/ )。我有一个外部命令链接到它,当调用它时,它会从另一个文件读
我有一个具有外部 API 的服务。在某些情况下我必须抛出 SecurityException。奇怪的事情如下:在某些 API 中,当我抛出异常时,绑定(bind)器成功完成此事务并且该异常被服务的经理
我有一个用 C# 编写的应用程序,它位于网络共享上。当我从本地驱动器运行它时,一切正常。当我从远程共享启动它时,调用像 try { System.Reflection.Assembly.Get
如果我自己的 DAO 类无法通过数据存储的身份验证,是否建议在其构造函数中抛出 SecurityException? Java 文档说 SecurityException 将由 SecurityMan
背景 我正在开发一款控制屏幕旋转的 Android 应用。 The app is available on the Google Play store .为了控制屏幕旋转,应用程序禁用了 system
这个问题在这里已经有了答案: Permission Denial: not allowed to send broadcast in android (4 个答案) 关闭 9 年前。 我的应用程序在
我尝试将位置服务作为后台服务运行。它在 Activity 中运行良好,但是当我使用服务时,我得到了 java.lang.securityException:客户端必须具有 ACCESS_COARSE_
我做了一个方法,当进度完成加载时发送本地通知,当我构建应用程序时,一切都清楚,没有任何错误/警告,我在发布 Google 控制台崩溃报告后收到了这个 通知方式如下: public void notif
我正在编写一个 Android 应用程序,作为该应用程序的一部分,我希望用户能够查看、选择和修改用户联系人。出于可用性原因(从用户方面),我的主要 Activity 扩展了 TabActivity。因
我在我的应用程序中使用带指纹的锁屏。虽然它可以与其他具有指纹传感器的手机无缝协作,但三星用户正面临一些 SecurityException,正如我在我的谷歌控制台报告中看到的那样。报告如下: java
我想制作一个能够将文件下载到计算机的小程序,然后在相关的编辑器中打开它们(当文件被保存时,应该会再次上传)。然而,在我花几个小时让它工作之前,我必须确保它实际上是可管理的(用 Java 桌面应用程序而
我的应用程序出现严重问题。我使用权限 android.permission.ACCESS_COARSE_LOCATION在广播接收器中,它运行完美。 但是在一定时间后(这似乎是随机的)应用程序崩溃并显
我在某些 API 6.0+ 设备上遇到以下崩溃: Fatal Exception: java.lang.SecurityException: Client must have ACCESS_COARS
我正在试验 Android AccountManager。 我有一个帐户身份验证服务,显示用于输入用户名/密码的 UI。 我转到设置/帐户/添加帐户,选择我的新帐户类型,然后我会看到 UI。 当我点击
使用此代码时出现上述错误: var userSettings = new UserSettings() { Username = TextBox
我似乎无法在 .NET 中写入事件日志。我得到以下异常: System.Security.SecurityException: The source was not found, but some o
我设计了一个函数,它可以从 SD 获取/设置资源,如果从 sd 中找不到,则从 Asset 中获取它,如果可能,将 Assets 写回 SD 此函数可以通过方法调用检查 SD 是否已安装且可访问...
FileStream 的 MSDN 构造函数表示它可能会抛出 UnauthorizedAccessException 或 SecurityException。以下是 MSDN 关于这些异常的说明。 U
我正在使用 Retrofit 的协程适配器,我发现,如果网络调用因为 URL 不正确而失败,则 try/catch block 将捕获它,但如果我删除 Internet 权限以便我们得到 Securi
我刚刚编写了一个 MVC 应用程序并让它在我的实验室中运行。现在我已将其部署到 GoDaddy,但收到以下错误。 Description: The application attempted to p
我是一名优秀的程序员,十分优秀!