今日、.NET 4.0ランタイム用に構築されたアプリケーションをリモートでデバッグしようとしたときに、奇妙な問題が発生しました。
アプリケーションはネットワーク共有上にあり、リモートマシンによって実行されます。ただし、System.Configuration.ConfigurationManager.GetSection()メソッドのアクセス許可要求によって発生したSecurityExceptionが原因で、ロード中にアプリケーションが毎回クラッシュします。基本クラスライブラリの他のアクセス許可の要求によってセキュリティ例外が発生するかどうかは確認していませんが、すべての場合において、これは新しいCLRでは発生しないはずです。
アプリケーションは完全に信頼されて実行されているため(デバッグ中にチェックし、CLR 4.0のイントラネットアプリケーションでは常にこれが当てはまる必要があります)、この場合、アクセス許可の要求によって例外が発生する可能性があります。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>